|
|

楼主 |
发表于 2023-7-2 13:43
|
显示全部楼层
本帖最后由 马黑黑 于 2023-7-2 13:53 编辑
帖子代码
- <style>
- #mydiv {
- margin: -80px 0 0 calc(50% - 593px);
- width: 1024px;
- height: 600px;
- background: url('https://638183.freep.cn/638183/t23/2/sea0a.jpg') no-repeat center/cover;
- box-shadow: 0 0 6px #000;
- overflow: hidden;
- position: relative;
- z-index: 1;
- --state: paused;
- }
- #mydiv::before {
- position: absolute;
- content: '';
- width: 178px;
- height: 187px;
- left: calc(50% - 66px);
- bottom: -20px;
- border-radius: 50%;
- cursor: pointer;
- transform: rotate(-90deg);
- z-index: 999;
- background: transparent url('https://files.superbed.cn/store/superbed/e8/61/64a0d24e1ddac507cc24e861.png') no-repeat;
- animation: swim 2s steps(6) infinite var(--state);
- }
- li-zi {
- display: block;
- position: absolute;
- left: 50%;
- bottom: 160px;
- width: 20px;
- height: 20px;
- background: snow;
- border-radius: 50%;
- animation: move 10s var(--delay) infinite alternate var(--state);
- --deg: 30deg; --xx: -200px; --delay: 0;
- }
- @keyframes move {
- from { transform: rotate(0deg) translateY(0px); opacity: 1; }
- to { transform: rotate(var(--deg)) translateY(var(--xx)); opacity: 0; }
- }
- @keyframes swim{
- 0%{ background-position:0px 0px; }
- 100%{ background-position:0px -1122px; }
- }
- </style>
- <div id="mydiv">
- <div class="tortoise"></div>
- </div>
- <audio id="aud" src="https://music.163.com/song/media/outer/url?id=27937368" autoplay="autoplay" loop="loop"></audio>
- <script>
- (function (){
- let total = 50;
- let createLizi = (mum,sons) => {
- Array.from({length: sons}).forEach( (s,k) => {
- let xx = 6 + Math.ceil(Math.random() * 10);
- s = document.createElement('li-zi');
- s.style.cssText += `
- width: ${xx}px;
- height: ${xx}px;
- left: calc(50% - ${xx / 2}px);
- --deg: ${50 - Math.ceil(Math.random() * 100)}deg;
- --xx: -${300 + Math.ceil(Math.random() * 600)}px;
- --delay: -${Math.random() * 20}s;
- `;
- mum.appendChild(s);
- });
- };
- createLizi(mydiv,total);
- let mState = () => mydiv.style.setProperty('--state', aud.paused ? 'paused' : 'running');
- aud.addEventListener('play', mState, false);
- aud.addEventListener('pause', mState, false);
- mydiv.onclick = () => aud.paused ? aud.play() : aud.pause();
- })();
- </script>
复制代码
|
|