本帖最后由 马黑黑 于 2024-3-22 13:33 编辑
帖子代码
<style>
#papa { margin: 0 0 0 calc(50% - 593px); width: 1024px; height: 640px; background: url('https://638183.freep.cn/638183/t24/1/30lp.jpg') no-repeat center/cover; box-shadow: 3px 3px 6px gray; overflow: hidden; position: relative; }
#canv { position: absolute; left: 50%; bottom: 4px; transform: translate(-50%,0); cursor: pointer; }
.pic { position: absolute; width: 240px; mix-blend-mode: screen; offset-path: path('M1124,280 Q750,-20 -100,70'); offset-distance: 100%; animation: fly 20s var(--delay) infinite var(--state); --delay: 0s; }
.pic:nth-of-type(2) { --delay: -7s; }
.pic:nth-of-type(3) { --delay: -14s; }
@keyframes fly { to { offset-distance: 0; } }
</style>
<div id="papa">
<img class="pic" src="https://638183.freep.cn/638183/t22/gif/bird1.gif" alt="" />
<img class="pic" src="https://638183.freep.cn/638183/t22/gif/bird1.gif" alt="" />
<img class="pic" src="https://638183.freep.cn/638183/t22/gif/bird1.gif" alt="" />
<canvas id="canv" width="600" height="240" title="点击播放"></canvas>
</div>
<script>
const aud = new Audio();
aud.src = 'https://yinpin.s3-us-east-1.ossfiles.com/30lp.mp3';
aud.crossOrigin = '';
aud.loop = true;
aud.load();
aud.play();
let AudioContext = window.AudioContext || window.webkitAudioContext;
let Ac = new AudioContext;
let analyser = Ac.createAnalyser();
analyser.fftSize = 256;
let source = Ac.createMediaElementSource(aud);
source.connect(analyser);
analyser.connect(Ac.destination);
let len = analyser.frequencyBinCount - 30;
let output = new Uint8Array(len);
let canvctx = canv.getContext('2d');
let ppWidth = canv.width / len;
let ppHeight, x;
let gradient = canvctx.createLinearGradient(0,0,0,200);
gradient.addColorStop(0,'rgba(128,0,0');
gradient.addColorStop(.5,'rgba(255,165,0');
gradient.addColorStop(1,'rgba(0,128,0');
(function draw() {
canvctx.clearRect(0, 0, canv.width, canv.height);
analyser.getByteFrequencyData(output);
x = 0.5;
for(let i = 0; i < len; i ++) {
ppHeight = output[ i ] * .9 + ppWidth;
canvctx.fillStyle = gradient;
canvctx.fillRect(x, canv.height - ppHeight, ppWidth - 1, ppHeight);
x += ppWidth;
}
requestAnimationFrame(draw);
})();
aud.onpause = aud.onplaying = () => aud.paused ?
(canv.title = '点击播放', papa.style.setProperty('--state', 'paused')) :
(canv.title = '点击暂停', papa.style.setProperty('--state', 'running'));
canv.onclick = () => aud.paused ? aud.play() : aud.pause();
</script>
|