Html+Css+js实现带有雪花飘落的许愿墙效果,首发10万字前端开发实战文档

本文介绍了使用HTML、CSS和JavaScript实现带有雪花飘落效果的许愿墙。通过JavaScript的Snowflake类控制雪花飘落,许愿墙的贴纸由for循环生成,内容可自定义。此外,提供了转换时间格式的函数和许愿墙的文字生成逻辑,适合前端开发者参考学习。
摘要由CSDN通过智能技术生成

功能要点介绍


1雪花飘落的代码是js控制的,可自行修改

2许愿墙的贴纸是for循环控制的,可自行修改

3文字是datas数组控制的,可以自行修改

代码部分


雪花逻辑部分(index.js)


class Snowflake {

constructor() {

this.x = 0;

this.y = 0;

this.vx = 0;

this.vy = 0;

this.radius = 0;

this.alpha = 0;

this.reset();

}

reset() {

this.x = this.randBetween(0, window.innerWidth);

this.y = this.randBetween(0, -window.innerHeight + 672);

this.vx = this.randBetween(-3, 3);

this.vy = this.randBetween(2, 5);

this.radius = this.randBetween(1, 4);

this.alpha = this.randBetween(0.1, 0.9);

}

randBetween(min, max) {

return min + Math.random() * (max - min);

}

update() {

this.x += this.vx;

this.y += this.vy;

if (this.y + this.radius > window.innerHeight) {

this.reset();

}

}

}

class Snow {

constructor() {

this.canvas = document.createElement(‘canvas’);

this.ctx = this.canvas.getContext(‘2d’);

document.body.appendChild(this.canvas);

window.addEventListener(‘resize’, () => this.onResize());

this.onResize();

this.updateBound = this.update.bind(this);

requestAnimationFrame(this.updat

  • 24
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值