本帖最后由 花简静 于 2024-8-18 15:28 编辑
<style>
#papa { margin: 130px 0 20px calc(50% - 931px); width: 1700px; height: 900px; background: #f1f1f1 url('https://642303.freep.cn/642303/tu/5y06.webp') no-repeat center/cover; box-shadow: 3px 4px 8px #000; overflow: hidden; z-index: 1; position: relative; --x: 0; --y: 0; }
#papa:hover #mplay { opacity: .5; }
#mplay { position: absolute; width: 120px; height: 120px; left: var(--x); top: var(--y); border: 1px solid #eee; border-radius: 50%; background: url('https://pic.imgdb.cn/item/65b11e61871b83018a790510.webp') no-repeat -10px -10px; opacity: 0; cursor: pointer; transition: 1s; animation: rot 5s linear infinite var(--state); display: grid; place-items: center; font-weight: bold; color: red; text-shadow: 1px 1px 2px white; }
#vid { position: absolute; left: 0; bottom: 0; width: 100%; height: calc(100% + 80px); object-fit: cover; mix-blend-mode: screen; pointer-events: none; }
#canv { position: absolute; mix-blend-mode: screen; opacity: .5; z-index: 2;}
@keyframes rot { to { transform: rotate(360deg); } }
</style>
<div id="papa">
<audio id="aud" src="https://music.163.com/song/media/outer/url?id=28699996" loop autoplay></audio>
<canvas id="mycanv" width="1700" height="900" style="border:0px solid gray"></canvas>
<video id="vid" src="https://img.tukuppt.com/video_show/2418175/00/18/94/5ef7a50c397ff.mp4" loop muted></video>
<div id="mplay">5·20</div>
</div>
<script>
var ww = mycanv.width, hh = mycanv.height, deg = -90, raf = null;
var ctx = mycanv.getContext('2d');
class ccText {
constructor(text) {
this.chars = text.split('');
this.colors = this.chars.map(color => `#${Math.random().toString(16).substr(4,4.95)}`);
};
draw(context) {
context.font = 'bold 40px sans-serif';
context.textAlign = 'center';
context.textBaseline = 'middle';
context.shadowOffsetX = -2;
context.shadowOffsetY = 2;
context.shadowColor = '#000';
context.shadowBlur = 4;
var a = 360 / this.chars.length, r1 = ww/2 - 620, r2 = hh/2 - 360;
this.chars.forEach((char,key) => {
var rad = (a * key + deg) * Math.PI / 180;
var x = ww/1.6 + r1 * Math.cos(rad), y = hh/1.25 + r2 * Math.sin(rad);
context.fillStyle = this.colors[key];
context.fillText(char, x, y);
});
};
};
var cc = new ccText('千山论坛朋友们五二〇快乐');
var render = () => {
aud.paused ? cancelAnimationFrame(raf) : raf = requestAnimationFrame(render);
ctx.clearRect(0, 0, ww, hh);
deg = (deg + 0.5) % 360;
cc.draw(ctx);
};
papa.onmousemove = (e) => {
if(e.target.id === 'mplay') return;
var x = e.offsetX, y = e.offsetY;
if(x < 60) x = 60;
if(x > papa.offsetWidth - 60) x = papa.offsetWidth - 60;
if(y < 60) y = 60;
if(y > papa.offsetHeight - 60) y = papa.offsetHeight - 60;
papa.style.setProperty('--x', `${x - 60}px`);
papa.style.setProperty('--y', `${y - 60}px`);
mplay.style.backgroundPosition = `-${x - 60}px -${y - 60}px`;
};
mplay.onclick = () => aud.paused ? aud.play() : aud.pause();
aud.onplaying = aud.onpause = () => mState();
aud.onseeked = () => cancelAnimationFrame(raf);
var mState = () => aud.paused ?
(papa.style.setProperty('--state', 'paused'), vid.pause(), cancelAnimationFrame(raf)) :
(papa.style.setProperty('--state', 'running'), vid.play(), render());
</script>
<BR><BR><BR><BR><BR><BR>
|