|
|

楼主 |
发表于 2024-2-11 12:59
|
显示全部楼层
帖子代码
- <style>
- #mydiv { margin: -70px 0 0 calc(50% - 593px); width: 1024px; height: 700px; background: url('https://638183.freep.cn/638183/t24/jpg/24u.jpeg') no-repeat center/cover; box-shadow: 3px 3px 8px #000; overflow: hidden; display: flex; flex-direction: row; gap: 50px; justify-content: center; align-items: end; position: relative; z-index: 1; }
- .trunk { position: relative; bottom: 0; width: 4px; height: 200px; background: linear-gradient(to top, black, tan, gray, tan); cursor: pointer; transform-origin: 50% 100%; animation: swear 3s infinite alternate var(--state); }
- .trunk::before { position: absolute; content: ''; width: 30px; height: 30px; background: radial-gradient(orange,darkred); border-radius: 50%; left: calc(50% - 15px); top: -30px; }
- .leaf { position: absolute; --angle: 45deg; }
- .leaf::before, .leaf::after { position: absolute; content: ''; left: -10px; width: 20px; height: 40px; border-radius: 50% 100%; transform-origin: 50% 100%; background: linear-gradient(80deg,lightgreen,green,lightgreen); transform: rotate(var(--angle)); }
- .leaf::after { --angle: -45deg; }
- .leaf:nth-of-type(2) { top: 20%; }
- .leaf:nth-of-type(3) { top: 50%; }
- @keyframes swear { from { transform: skew(3deg); } to { transform: skew(-4deg); } }
- </style>
- <div id="mydiv">
- <audio id="aud" src="https://music.163.com/song/media/outer/url?id=29393038" autoplay loop></audio>
- <img style="position: absolute; top: 0;" src="https://638183.freep.cn/638183/Pic/81/bird3.gif" alt="" />
- </div>
- <script>
- (function () {
- var total = Math.floor(mydiv.offsetWidth / 60);
- Array.from({length: total}).forEach((item,key) => {
- item = document.createElement('div');
- item.className = 'trunk';
- item.style.animationDelay = -1.5 * Math.random() + 's';
- item.style.height = Math.random() * 120 + 120 + 'px';
- item.innerHTML = '<div class="leaf"></div>'.repeat(3);
- item.onclick = () => aud.paused ? aud.play() : aud.pause();
- mydiv.append(item);
- });
- })();
- var mState = () => mydiv.style.setProperty('--state', aud.paused ? 'paused' : 'running');
- aud.addEventListener('pause', mState);
- aud.addEventListener('playing',mState);
- </script>
复制代码
|
|