|
本帖最后由 红英 于 2023-12-28 20:50 编辑
<style> #papa { margin: auto; width: 1024px; height: 640px; background: url('https://s11.ax1x.com/2023/12/26/pibeTyQ.jpg') no-repeat center/cover; box-shadow: 3px 3px 20px #000; overflow: hidden; position: relative; z-index: 1; } #mypic { position: absolute; width: 300px; cursor: pointer; animation: rot 6s infinite linear var(--state); } @keyframes rot { to { transform: rotate(360deg); } } </style>
<div id="papa"> <img id="mypic" src="https://s11.ax1x.com/2023/12/28/piqvw2q.png" alt="" /> <audio id="aud" src="https://music.163.com/song/media/outer/url?id=5280145.mp3" autoplay loop></audio> </div>
<script> let mState = () => papa.style.setProperty('--state', aud.paused ? 'paused' : 'running'); aud.addEventListener('pause', () => mState()); aud.addEventListener('playing', () => mState()); mypic.onclick = () => aud.paused ? aud.play() : aud.pause(); </script>
|
|