雪花代码-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 分钟前
Nginx 基本使用和高级用法详解
运维·javascript·nginx
蒙特卡洛的随机游走12 分钟前
Spark的宽依赖与窄依赖
大数据·前端·spark
共享家952718 分钟前
QT-常用控件(多元素控件)
开发语言·前端·qt
幸运小圣19 分钟前
Iterator迭代器 【ES6】
开发语言·javascript·es6
葱头的故事20 分钟前
将传给后端的数据转换为以formData的类型传递
开发语言·前端·javascript
中微子31 分钟前
🚀 2025前端面试必考:手把手教你搞定自定义右键菜单,告别复制失败的尴尬
javascript·面试
_233332 分钟前
vue3二次封装element-plus表格,slot透传,动态slot。
前端·vue.js
jump68035 分钟前
js中数组详解
前端·面试
崽崽长肉肉38 分钟前
iOS 基于Vision.framework从图片中提取文字
前端
温宇飞44 分钟前
Web Abort API - AbortSignal 与 AbortController
前端