|
|

楼主 |
发表于 2022-8-12 12:57
|
显示全部楼层
本帖最后由 马黑黑 于 2022-8-12 13:44 编辑
参考代码(完整):
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
- <html>
- <head>
- <title>王菲 - 流星</title>
- </head>
- <body>
- <style>
- #papa { left: -214px; width: 1024px; height: 640px; background: gray url('https://638183.freep.cn/638183/Pic/81/nightsky.jpg') no-repeat center/cover; box-shadow: 3px 3px 20px #000; overflow: hidden; position: relative; }
- #disc { position: absolute; width: 40px; height: 40px; left: 10px; bottom: 10px; 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; }
- #lrcbox { position: absolute; left: 60px; bottom: 10px; font: bold 22px / 40px sans-serif; color: lightblue; text-shadow: 2px 2px 4px #222; }
- #canv { position: absolute; width: 1024px; height: 350px; left: 0; top: 0; }
- @keyframes rot { to { transform: rotate(360deg); } }
- </style>
- <div id="papa">
- <span id="lrcbox">Loading ...</span>
- <canvas id="canv" width="1024" height="350"></canvas>
- <span id="disc"></span>
- </div>
- <script>
- let ctx = canv.getContext('2d');
- let w = canv.width, h = canv.height;
- let num = (m, n) => Math.floor(Math.random() * (n - m + 1) + m);
- let stars = new Array(500), meteors = new Array(10);
- let aud = new Audio();
- let lrcAr = [
- ['0.06','王菲 - 流星'],
- ['1.06','词:周耀辉'],
- ['2.06','曲:刘以达'],
- ['26.04','我在海角你却在天边'],
- ['31.06','两颗注定一起出现的星星'],
- ['37.05','遥遥呼应却永远走不近'],
- ['42.09','我和你在暗中互相辉映'],
- ['48.07','究竟这样是缠绵还是互相毁灭'],
- ['59.06','已经太久无法承受'],
- ['65.06','我要逃出你这温柔的宇宙'],
- ['74.02','化作一颗流星不管飞向那里'],
- ['79.10','我身后有闪烁的回忆'],
- ['85.09','我是一颗流星 我有一个希望 离开你'],
- ['93.05','我自己美丽地消逝'],
- ['123.03','我们之间像没有甚幺'],
- ['128.07','只有一样流着眼泪的银河'],
- ['134.05','你是牛郎我不敢做织女'],
- ['139.08','我不要延续凄凉的诗歌'],
- ['145.09','不想这样的缠绵'],
- ['150.07','不要互相毁灭'],
- ['156.06','已经太久无法承受'],
- ['162.03','是我再次回到凡尘的时候'],
- ['171.04','化作一颗流星不管飞向哪里'],
- ['176.10','我身后有闪烁的回忆'],
- ['182.05','我是一颗流星只有一个希望离开你'],
- ['190.01','我自己'],
- ['195.04','美丽化作一颗流星不管飞向哪里'],
- ['202.06','我身后有你我的回忆'],
- ['208.02','数不尽的流星只有一个希望'],
- ['213.10','我寻找'],
- ['216.02','我自己美丽故事']
- ];
- aud.loop = true;
- aud.autoplay = true;
- aud.src = 'https://music.163.com/song/media/outer/url?id=37993018.mp3';
- 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');
- aud.addEventListener('timeupdate',function(){
- let tt = aud.currentTime;
- for(j=0; j<lrcAr.length; j++){
- if(tt >= lrcAr[j][0]) lrcbox.innerHTML = lrcAr[j][1];
- }
- });
- function Star() {
- this.x = num(3, w - 3);
- this.y = num(3, h -3);
- this.r = num(1,3) * .5;
- this.a = num(1, 10) * 0.1;
- this.speedA = 0.01;
- this.color = 'rgba(153, 204, 255, .6)';
- }
- Star.prototype = {
- create: function() {
- ctx.beginPath();
- ctx.fillStyle = this.color;
- ctx.arc(this.x, this.y, this.r, 0, Math.PI * 2);
- ctx.fill();
- },
- flash: function() {
- this.a += this.speedA;
- if(this.a > 1 || this.a < 0) this.speedA = -this.speedA;
- this.color = 'rgba(153, 204, 255, ' + this.a + ')';
- this.create();
- },
- drop: function() {
- this.x += 2;
- this.y += 2;
- this.a = .45;
- if(this.x > w - 3 || this.y > h - 3) {
- this.x = num(3, w - 3);
- this.y = num(3, h -3);
- }
- }
- };
- for(let x = 0; x < stars.length; x++) {
- let star = new Star();
- stars[x] = star;
- }
- for(let x = 0; x < meteors.length; x ++) meteors[x] = num(0,stars.length - 1);
- (function render() {
- ctx.globalCompositeOperation = 'destination-out';
- ctx.fillStyle = 'rgba(0,0,0,.1)';
- ctx.fillRect(0,0,w,h);
- ctx.globalCompositeOperation = 'lighter';
- for(let x of stars) x.flash();
- for(let x of meteors) stars[x].drop();
- requestAnimationFrame(render);
- })();
- </script>
- </body>
- </html>
复制代码
|
|