雪花代码-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>
相关推荐
空中海2 分钟前
第四章:Vue Router
前端·javascript·vue.js
竹林8183 分钟前
从零集成RainbowKit:我如何在一个周末搞定多链钱包连接并填平三个大坑
前端·javascript
2601_953465614 分钟前
M3U8 在线播放器:无需安装,一键调试 HLS 直播流
开发语言·前端·javascript·开发工具·m3u8·m3u8在线播放
qq_12084093717 分钟前
Three.js 工程向:资源生命周期管理与显存回收实践
前端·javascript·orbitcontrols
MaoziShan8 分钟前
CMU Subword Modeling | 23 Syllables and Syllabification
前端·人工智能·机器学习·语言模型·自然语言处理·中文分词
M ? A11 分钟前
VuReact 1.6.2 发布,新一代 Vue 3 转 React 编译工具
前端·javascript·vue.js·react.js·面试·开源·vureact
Nicander17 分钟前
vibe-coding 项目:中文字体子集化工具(纯前端)
前端
老王以为19 分钟前
Vue & React 服务端渲染深度分析
前端·vue.js·react.js
捧月华如20 分钟前
TypeScript:给JavaScript加上类型安全
javascript·ubuntu·typescript
im_AMBER22 分钟前
协同文档丢失?Yjs状态漂移与三层防线
前端·react.js·架构