|
|

楼主 |
发表于 2022-8-10 07:17
|
显示全部楼层
代码分享:
- <style>
- #papa { left: -214px; width: 1024px; height: 640px;background: rgba(0,0,0,.65) url('https://638183.freep.cn/638183/Pic/38/lake5.jpg') no-repeat center/cover; box-shadow: 3px 3px 20px #000; display: grid; place-items: center; position: relative; }
- #mama { position: absolute; width: 600px; height: 600px; right: 20px; }
- #canv { position: absolute; border-radius: 50%; }
- #disc { position: absolute; width: 40px; height: 40px; left: 10px; top: 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; }
- #tit { position: absolute; left: 60px; top: 10px; font: bold 22px / 40px sans-serif; color: snow; text-shadow: 2px 2px 4px black; }
- @keyframes rot { to { transform: rotate(360deg); } }
- </style>
- <div id="papa">
- <div id="mama"><canvas id="canv"></canvas></div>
- <span id="disc"></span>
- <span id="tit">风止</span>
- </div>
- <script>
- let ctx = canv.getContext('2d');
- let w = canv.width = mama.offsetWidth, h = canv.height = mama.offsetHeight;
- let objAr = new Array(50), speed = 1, curve = 0.45, idx = 0, aud = new Audio();
- let num = (min, max) => Math.floor(Math.random() * (max-min+1)) + min;
- aud.src = 'https://music.163.com/song/media/outer/url?id=1947739273.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');
- for(let k = 0; k < objAr.length; k ++) {
- let cc = `rgba(${num(0,255)}, ${num(0,255)}, ${num(0,255)}, .75)`;
- objAr[k] = new Obj(w/2, h/2, 2, k*360/objAr.length, cc);
- }
- function Obj(x,y,size,angle,color) {
- this.x = x;
- this.y = y;
- this.size = size;
- this.angle = angle;
- this.color = color;
- }
- Obj.prototype.draw = function() {
- ctx.beginPath();
- ctx.fillStyle = this.color
- ctx.arc(this.x, this.y, this.size, 0, 2 * Math.PI);
- ctx.fill();
- }
- Obj.prototype.move = function() {
- let rad = this.angle * Math.PI / 180;
- this.x += Math.cos(rad) * speed;
- this.y += Math.sin(rad) * speed;
- this.angle += curve;
- }
- function render() {
- idx ++;
- if(idx > 800) ctx.clearRect(0,0,w,h);
- if(idx > 1600) idx = 0;
- for(item of objAr) {
- item.draw();
- item.move();
- }
- requestAnimationFrame(render);
- }
- render();
- </script>
复制代码
|
|