雪花代码-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>
相关推荐
代码老中医10 分钟前
接手老项目的一个月,我重构了那个2000行的“祖传”React组件
前端
飘逸飘逸20 分钟前
Autojs进阶前言
android·javascript
叫我一声阿雷吧27 分钟前
JS 入门通关手册(01)|零基础入门:JavaScript 到底是什么?学完能干嘛?
javascript·前端入门·js入门
用户830407130570139 分钟前
路由传参刷新丢失问题:三种解决方案与最佳实践
前端
从文处安42 分钟前
「前端何去何从」高效提示词(prompts):前端开发者的AI协作指南
前端·aigc
大时光43 分钟前
gsap--《pink老师vivo官网实现》
前端
www_stdio1 小时前
全栈项目第五天:构建现代企业级 React 应用:从工程化到移动端实战的全链路指南
前端·react.js·typescript
my_styles1 小时前
window系统安装/配置Nginx
服务器·前端·spring boot·nginx
神奇的程序员1 小时前
不止高刷:明基 RD280UG 在编码场景下的表现如何
前端
Rabbit_QL1 小时前
【音频处理】从 AirPods 主动降噪到音频 Source Separation:同一个问题的两种工程解法
前端·人工智能·音视频