|
|

楼主 |
发表于 2022-8-15 07:28
|
显示全部楼层
代码分享(全):
- <style>
- #papa { margin: auto; display: grid; place-items: center; width: 1024px; height: 640px; background: url('https://638183.freep.cn/638183/Pic/38/333.png') no-repeat center/cover; position: relative; }
- #canv { position: absolute; }
- #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: snow; text-shadow: 2px 2px 4px #222; }
- @keyframes rot { to { transform: rotate(360deg); } }
- </style>
- <div id="papa">
- <span id="lrcbox">失真的梦</span>
- <canvas id="canv"></canvas>
- <span id="disc"></span>
- </div>
- <script type="text/javascript">
- let num = (min, max) => Math.floor(Math.random() * (max-min+1)) + min;
- let r = 10, speed = 0.5, idx = 0;
- let w = canv.width = 500, h = canv.height = 600;
- let ctx = canv.getContext('2d');
- let images = new Array(), aud = new Audio();
- aud.src = 'https://music.163.com/song/media/outer/url?id=1425398486.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 preload() {
- for (j = 0; j < preload.arguments.length; j++) {
- images[j] = new Image()
- images[j].src = preload.arguments[j]
- }
- }
- preload(
- 'https://638183.freep.cn/638183/Pic/38/3-1.jpg',
- 'https://638183.freep.cn/638183/Pic/38/3-2.jpg',
- 'https://638183.freep.cn/638183/Pic/38/3-3.jpg',
- 'https://638183.freep.cn/638183/Pic/38/3-4.jpg',
- 'https://638183.freep.cn/638183/Pic/38/3-5.jpg',
- 'https://638183.freep.cn/638183/Pic/38/3-6.jpg',
- 'https://638183.freep.cn/638183/Pic/38/3-7.jpg',
- 'https://638183.freep.cn/638183/Pic/38/3-8.jpg',
- 'https://638183.freep.cn/638183/Pic/38/3-9.jpg',
- 'https://638183.freep.cn/638183/Pic/38/3-10.jpg',
- )
- idx = num(0, images.length - 1);
- (function draw() {
- ctx.clearRect(0, 0, w, h);
- ctx.save();
- ctx.beginPath();
- ctx.arc(w / 2, h / 2, r, 0, Math.PI*2);
- ctx.closePath();
- ctx.fillStyle = "transparent";
- ctx.fill();
- ctx.clip();
- ctx.drawImage(images[idx], 0, 0, w, h);
- ctx.restore();
- r += speed;
- if (r > 250 || r <= 0) speed = -speed;
- if(r <= 0) idx = num(0, images.length - 1);
- requestAnimationFrame(draw);
- })();
- </script>
复制代码
|
|