雪花代码-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>
相关推荐
布列瑟农的星空4 分钟前
rsbuild mock 插件开发指南
前端
用泥种荷花19 分钟前
【LangChain.js学习】 文档加载(Loader)与文本分割全解析
前端
cxxcode1 小时前
Vite 热更新(HMR)原理详解
前端
HelloReader1 小时前
Tauri 架构从“WebView + Rust”到完整工具链与生态
前端
UIUV1 小时前
node:child_process spawn 模块学习笔记
javascript·后端·node.js
Bigger1 小时前
告别版本焦虑:如何为 Hugo 项目定制专属构建环境
前端·架构·go
烛阴2 小时前
Three.js 零基础入门:手把手打造交互式 3D 几何体展示系统
javascript·webgl·three.js
颜酱2 小时前
单调栈:从模板到实战
javascript·后端·算法
代码匠心3 小时前
AI 自动编程:一句话设计高颜值博客
前端·ai·ai编程·claude
_AaronWong4 小时前
Electron 实现仿豆包划词取词功能:从 AI 生成到落地踩坑记
前端·javascript·vue.js