雪花代码-html版

雪花代码

动画效果

代码

javascript 复制代码
<!DOCTYPE html>

<html>

<head>

<style>

body {

background-color: #000000;

}

.snowflake {

position: absolute;

font-size: 10px;

color: #FFFFFF;

text-shadow: 1px 1px 1px #000000;

user-select: none;

}

</style>

</head>

<body>

<script>

function random(min, max) {

return Math.floor(Math.random() * (max - min + 1)) + min;

}

function Snowflake() {

this.characters = "❄️";

this.x = random(0, window.innerWidth);

this.y = random(-200, -100);

this.speed = random(1, 5);

this.element = document.createElement("span");

this.element.classList.add("snowflake");

this.element.innerHTML = this.characters;

document.body.appendChild(this.element);

}

Snowflake.prototype.update = function() {

this.y += this.speed;

this.element.style.top = this.y + "px";

this.element.style.left = this.x + "px";

if (this.y > window.innerHeight) {

this.y = random(-200, -100);

this.x = random(0, window.innerWidth);

}

};

var snowflakes = [];

for (var i = 0; i < 100; i++) {

snowflakes.push(new Snowflake());

}

setInterval(function() {

snowflakes.forEach(function(snowflake) {

snowflake.update();

});

}, 50);

</script>

</body>

</html>
相关推荐
N***73854 分钟前
JavaScript物联网案例
开发语言·javascript·物联网
一个处女座的程序猿O(∩_∩)O13 分钟前
React Router 路由模式详解:HashRouter vs BrowserRouter
前端·react.js·前端框架
Caster_Z39 分钟前
WinServer安装NPM(Nginx Proxy Manager),并设置反向代理和开启https
前端·nginx·npm
顾安r41 分钟前
11.22 脚本 手机termux项目分析(bash)
前端·python·stm32·flask·bash
慧慧吖@44 分钟前
Zustand
开发语言·javascript·ecmascript
2***B4491 小时前
JavaScript语音识别案例
开发语言·javascript·语音识别
是你的小橘呀1 小时前
JavaScript 原型链解密:原来 proto 和 prototype 这么好懂
前端·javascript·前端框架
ohyeah1 小时前
使用 LocalStorage 实现本地待办事项(To-Do)列表
前端·javascript
Jing_Rainbow1 小时前
【前端三剑客-6/Lesson11(2025-10-28)构建现代响应式网页:从 HTML 到 CSS 弹性布局再到 JavaScript 交互的完整指南 🌈
前端·javascript
6***37941 小时前
JavaScript虚拟现实开发
开发语言·javascript·vr