2002年的第一场雪 - 刀郎 TO:三月的阳光
本帖最后由 宁静 于 2023-2-22 15:19 编辑 <br /><br /><style>#papa { left: -180px; width: 1191px; height: 742px; top: 150px; box-shadow: 3px 3px 20px #000; position: relative; }
#canvas { position: absolute; top: 0; left: 0; }
#disc { position: absolute; width: 60px; height: 60px; left: 110px; top: 600px; background: conic-gradient(red,orange,yellow,green,teal,blue,purple); mask: radial-gradient(transparent 4px,red 0); -webkit-mask: radial-gradient(transparent 4px,red 0); border-radius: 50%; cursor: pointer; animation: rot 2s linear infinite; }
#imgSnow, #bgSnow { display: none; }
#tit { position: absolute; left: 360px; top: 610px;font: bold 25px / 40px sans-serif; color: snow; text-shadow: 2px 2px 4px black; }
@keyframes rot { to { transform: rotate(360deg); } }
</style>
<div id="papa">
<canvas id="canvas"></canvas>
<img id="imgSnow" src="https://pic.imgdb.cn/item/62f32a1616f2c2beb12d3f67.png" alt="">
<img id="bgSnow" src="https://pic.imgdb.cn/item/62f329ee16f2c2beb12cb787.jpg" alt="">
<span id="disc"></span>
<span id="tit">2002年的第一场雪 - 刀郎</span>
</div>
<script>
let aud = new Audio();
aud.src = 'https://music.163.com/song/media/outer/url?id=77437.mp3';
aud.loop = true;
aud.autoplay = true;
disc.style.animationPlayState = aud.paused ? 'paused' : 'running';
disc.onclick = () => aud.paused ? aud.play() : aud.pause();
aud.addEventListener('playing',()=> disc.style.animationPlayState = 'running');
aud.addEventListener('pause',()=> disc.style.animationPlayState = 'paused');
(function () {
let ctx = canvas.getContext('2d');
let snowArray = {}; //雪花对象
let snowIndex = 0; //标识符
let setting = {
num: 100, //数量
snowSize: 20, //大小
startX: Math.random() * canvas.width, //起始横坐标
startY: 0, //起始纵坐标
vy: 0.01
}
canvas.width = papa.offsetWidth;
canvas.height = papa.offsetHeight;
function snow() {
this.x = Math.random() * canvas.width; // 起始横坐标
this.y = setting.startY; // 起始纵坐标
this.size = setting.snowSize + Math.random() * 10 - 10; //大小
this.vx = Math.random() * 3 - 2; //横坐标偏移量
this.vy = Math.random() * 10; //纵坐标偏移量
this.life = 0;
this.maxLife = 100;
this.id = snowIndex;
snowArray = this; //当前信息保存至对象snowArray
snowIndex ++;
}
snow.prototype.draw = function () {
this.x += this.vx;
this.y += this.vy;
this.vy += setting.vy;
this.life ++;
if (this.y > canvas.height * 0.9 - 20 || this.life >= this.maxLife) snowArray;
ctx.drawImage(imgSnow, this.x, this.y, this.size, this.size)
}
function render() {
ctx.drawImage(bgSnow, 0, 0, canvas.width, canvas.height);
for (let j = 0; j < setting.num; j++) {
if (Math.random() > 0.97) new snow();
}
for (let j in snowArray) {
snowArray.draw();
}
requestAnimationFrame(render);
}
render();
})();
</script>
<br><br><br><br><br><br><br><br><br><br><br> @三月的阳光 谢谢阳光 这么忙还送礼,刚学的下雪效果,送给阳光。。。。 这个制作比较简单,不要嫌弃。心意满满{:10_401:}
顺祝阳光工作顺利,劳逸结合,保重身体。。。。。 太美了,听会儿在下{:10_402:} 浅笑 发表于 2022-8-11 12:28
太美了,听会儿在下
笑笑好,赶快下了去午休。。。。{:10_401:}
蹭听一下,{:10_402:} 曾经的经典 这首歌我翻唱过
这雪下的不小{:9022:}