雪花代码-html版

雪花代码

动画效果

在这里插入图片描述

代码

<!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. TCP协议是安全的吗?

    2024-01-12 14:56:01       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-12 14:56:01       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-12 14:56:01       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-12 14:56:01       18 阅读

热门阅读

  1. 算法习题练习

    2024-01-12 14:56:01       28 阅读
  2. .net core 6 集成和使用 mongodb

    2024-01-12 14:56:01       36 阅读
  3. 【大数据面试】常见数仓建模面试题附答案

    2024-01-12 14:56:01       32 阅读
  4. vue3知识盲点总结

    2024-01-12 14:56:01       28 阅读
  5. js中console.log()的使用方法

    2024-01-12 14:56:01       35 阅读
  6. 箭头函数与普通函数的差异

    2024-01-12 14:56:01       33 阅读
  7. Django身份验证初试

    2024-01-12 14:56:01       43 阅读
  8. 两两交换链表中的节点【链表】

    2024-01-12 14:56:01       38 阅读