|
|

楼主 |
发表于 2022-8-14 07:51
|
显示全部楼层
参考代码(全)
- <style>
- #papa { left: -214px; width: 1024px; height: 640px; background: black url('/data/attachment/forum/202208/14/074919yeeelef1ee9yj1en.jpg') no-repeat center/cover; box-shadow: 3px 3px 20px #000; position: relative; }
- #canv { position: absolute; opacity: .75; }
- #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: #859670; text-shadow: 2px 2px 4px #222; }
- @keyframes rot { to { transform: rotate(360deg); } }
- </style>
- <div id="papa">
- <span id="lrcbox">黑客帝国</span>
- <canvas id="canv" width="1024" height="640"></canvas>
- <span id="disc"></span>
- </div>
- <script type="text/javascript">
- let ctx = canv.getContext('2d');
- let w = canv.width, h = canv.height;
- let texts = Array.from(Array(94), (x,k) => String.fromCharCode(33+k)),
- fontsize = 16,
- columns = Math.floor(w / fontsize) - 1,
- drops = new Array(columns),
- aud = new Audio();
-
- aud.src = 'https://music.163.com/song/media/outer/url?id=1809135506.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 draw(){
- ctx.fillStyle = 'rgba(0, 0, 0, 0.1)';
- ctx.fillRect(0, 0, w, h);
- ctx.fillStyle = '#0f0';
- ctx.font = fontsize + 'px arial';
- for(var j = 0; j < drops.length; j ++){
- let text = texts[Math.floor(Math.random() * texts.length)];
- ctx.fillText(text, j * fontsize + fontsize / 2 + 1, drops[j] * fontsize);
- if(drops[j]*fontsize > h || Math.random() > 0.95){
- drops[j] = 0;
- }
- drops[j]++;
- }
- requestAnimationFrame(draw);
- })();
- </script>
复制代码
|
|