html代码特效银河系源代码
时间: 2023-11-03 19:06:02 浏览: 58
以下是一个简单的 HTML 代码,可以实现银河系特效:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>银河系特效</title>
<style>
body {
background-color: black;
}
.stars {
position: absolute;
width: 1px;
height: 1px;
background-color: white;
box-shadow: 0 0 2px white;
}
.galaxy {
position: relative;
width: 100%;
height: 100vh;
overflow: hidden;
}
.galaxy:before {
content: "";
position: absolute;
width: 100%;
height: 100%;
background-image: radial-gradient(ellipse at center, rgba(255,255,255,0) 0%, rgba(0,0,0,0.75) 100%);
z-index: 1;
}
.galaxy:after {
content: "";
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 800px;
height: 800px;
background-image: radial-gradient(ellipse at center, rgba(255,255,255,0.15) 0%, rgba(0,0,0,0.75) 100%);
border-radius: 50%;
z-index: 1;
}
</style>
</head>
<body>
<div class="galaxy">
<script>
for (var i = 0; i < 500; i++) {
var star = document.createElement("div");
star.classList.add("stars");
star.style.left = Math.random() * 100 + "%";
star.style.top = Math.random() * 100 + "%";
star.style.animationDelay = Math.random() + "s";
document.body.appendChild(star);
}
</script>
</div>
</body>
</html>
```
你可以将这段代码复制粘贴到一个 HTML 文件中,并在浏览器中打开它,就可以看到银河系特效了。