|
|

楼主 |
发表于 2022-8-24 08:53
|
显示全部楼层
代码分享(全):
- <style>
- #papa { left: -214px; width: 1024px; height: 640px; display: grid; place-items: center; box-shadow: 3px 3px 20px #000; opacity: .95; position: relative; z-index: 3; }
- #lrcbox { position: absolute; top: 20px; font: normal 1.8em sans-serif; color: #50616d; text-shadow: 1px 1px 2px #000, -5px -5px 10px rgba(0,0,0,.65); }
- #disc { position: absolute; width: 40px; height: 40px; left: 507px; top: 302px; background: conic-gradient(red,orange,yellow,green,teal,blue,purple); mask: radial-gradient(transparent 5px,red 0); -webkit-mask: radial-gradient(transparent 5px,red 0); border-radius: 50%; cursor: pointer; z-index: 10; animation: rot 2s linear infinite; }
- #canv { margin: auto; display: block; position: relative; border: 1px solid; }
- @keyframes rot { to { transform: rotate(360deg); } }
- </style>
- <div id="papa">
- <canvas id="canv"></canvas>
- <span id="disc"></span>
- </div>
- <script>
- let ctx = canv.getContext('2d'), mypic = new Image(), aud = new Audio();
- let w = canv.width = papa.offsetWidth, h = canv.height = papa.offsetHeight;
- let num = (x,y) => Math.floor(Math.random() * (x - y + 1) + y);
- mypic.src = 'https://638183.freep.cn/638183/Pic/2022/zhuzi.jpg';
- mypic.onload = () => draw();
- aud.src = 'https://music.163.com/song/media/outer/url?id=449578097.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');
- aud.addEventListener('timeupdate', () => draw());
- function draw() {
- ctx.clearRect(0, 0, canv.width, canv.height);
- ctx.drawImage(mypic, 0, 0, w, h);
- ctx.shadowOffsetX = 4;
- ctx.shadowOffsetY = 4;
- ctx.shadowBlur = 8;
- ctx.shadowColor = 'rgba(0,0,0,.5)';
- ctx.font = 'bold 60px sans-serif';
- ctx.textAlign = 'center';
- ctx.textBaseline = 'middle';
-
- for(j = 0; j < 100; j ++) {
- ctx.fillStyle = 'hsla(' + num(0,360) + ', 100%, 50%, 0.65)';
- let r = num(20, 5), x = num(r, canv.width - r), y = num(r, canv.height - r);
- ctx.beginPath();
- ctx.arc(x, y, r, 0, Math.PI * 2);
- ctx.fill();
- }
- ctx.strokeStyle = 'hsl(' + num(0, 360) + ', 100%, ' + num(20, 80) + '%)';
- ctx.beginPath();
- ctx.strokeText('钻石 世界', canv.width / 2 + 15, canv.height / 2);
- }
- </script>
复制代码
|
|