雪花代码-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>
相关推荐
子春一1 分钟前
Flutter for OpenHarmony:构建一个优雅的 Flutter 每日一句应用,深入解析状态管理、日期驱动内容与 Material 3 交互动效
javascript·flutter·交互
qq_336313932 分钟前
javaweb-Ajax
前端·javascript·ajax
豆约翰3 分钟前
句子单词统计 Key→Value 动态可视化
开发语言·前端·javascript
weixin_456907414 分钟前
CSS DSF.soolCXZ LsoolbDSF:html 中 doos() 的 Copy-goos-Prite 实现实验笔记
css·笔记·html
摘星编程4 分钟前
OpenHarmony环境下React Native:useState函数式更新
javascript·react native·react.js
步达硬件6 分钟前
【Matlab】修改视频尺寸
前端·matlab·音视频
咕噜咕噜啦啦7 分钟前
CSS3基础
前端·css·css3
抵梦7 分钟前
NPM、CNPM、PNPM:Node.js 依赖工具对比与选择
前端·npm·node.js
⑩-7 分钟前
HTML期末课设作业
css·html
CamilleZJ12 分钟前
多端ui方案
前端·ui