朵拉 发表于 2023-3-22 21:21

化身孤岛的鲸(马黑黑原创)

本帖最后由 朵拉 于 2023-3-22 21:36 编辑 <br /><br /><style>
#papa {
      --state: paused;
      --s1: 0.8; --s2: 1.6;
      margin: -80px 0 0 calc(50% - 593px);
      display: grid;
      place-items: center;
      width: 1024px;
      height: 640px;
      background: lightblue url('https://pic.imgdb.cn/item/641affeea682492fcce9a002.webp') no-repeat center/cover;
      box-shadow: 6px 3px 20px #000;
      user-select: none;
      position: relative;
      z-index: 1;
}
#papa::before {
      position: absolute;
      content: '';
      width: 200px;
      height: 200px;
      background: transparent;
      box-shadow: var(--boxsd);
      border-radius: 50%;
}
#papa:fullscreen { --s1: 1; --s2: 2; }
#papa:fullscreen .ball { width: 20px; height: 20px; }
#mplayer {
      position: absolute;
      width: 140px;
      height: 140px;
      display: grid;
      place-items: center;
      cursor: pointer;
      animation: change 18s linear infinite alternate var(--state);
}
.ball {
      position: absolute;
      width: 15px;
      height: 15px;
      border-radius: 50%;
      box-shadow: -5px 0 10px hsla(0,0%,0%,.42) inset;
}
#btnFs {
      position: absolute;
      bottom: 20px;
      width: fit-content;
      height: fit-content;
      padding: 6px;
      border-radius: 6px;
      border: 2px solid snow;
      color: snow;
      text-shadow: 1px 1px 1px #000;
      display: none;
      cursor: pointer;
}
@keyframes flash { to { box-shadow: 0 0 100px 60px hsla(240, 100%,50%, .2), -2px -2px 8px snow inset; } }
@keyframes change {
      from { transform: perspective(3000px) translateZ(-360px) rotateX(-15deg) rotateY(-30deg) rotateZ(0) scale(var(--s1)); }
      to { transform: perspective(3000px) translateZ(360px) rotateX(15deg) rotateY(30deg) rotateZ(3turn) scale(var(--s2)); }
}
</style>

<div id="papa">
      <div id="mplayer"></div>
      <div id="btnFs">全屏观赏</div>
      <audio id="aud" src="https://music.163.com/song/media/outer/url?id=1465313631.mp3" autoplay loop></audio>
</div>

<script>
(function() {
      let total = 18, fs = false, timerId, boxTimer;
      for(let i = 0; i < total; i ++) {
                let ball = document.createElement('span');
                ball.className = 'ball';
                ball.style.cssText += `
                        background: #${Math.random().toString(16).substr(-6)};
                        transform: rotate(${360/total*i}deg) translate(70px);
                        animation: flash ${Math.random()+0.1}s infinite alternate var(--state);
                `;
                mplayer.appendChild(ball);
      }

      let flash = () => {
                clearTimeout(boxTimer);
                papa.style.setProperty('--boxsd', `
                        ${Math.random()*100 - 500}px 0 60px #${Math.random().toString(16).substr(-6)},
                        ${Math.random()*100 - 350}px 0 60px #${Math.random().toString(16).substr(-6)},
                        ${Math.random()*100 + 250}px 0 60px #${Math.random().toString(16).substr(-6)},
                        ${Math.random()*100 + 400}px 0 60px #${Math.random().toString(16).substr(-6)}`);
                boxTimer = setTimeout(flash,120);
      };

      let mState = () => aud.paused ? (papa.style.setProperty('--state','paused'), clearTimeout(boxTimer)) : (papa.style.setProperty('--state','running'), flash());
      mplayer.onclick = () => aud.paused ? aud.play() : aud.pause();
      aud.addEventListener('play', () => mState());
      aud.addEventListener('pause', () => mState());
      aud.addEventListener('ended', () => playNext());
      papa.addEventListener('mousemove', (e) => {
                clearTimeout(timerId);
                btnFs.style.display = 'block';
                timerId = setTimeout('btnFs.style.display = "none"', 3000);
      });
      btnFs.addEventListener('click', () => fs ? document.exitFullscreen() : papa.requestFullscreen());
      document.addEventListener('fullscreenchange', () => document.fullscreenElement !== null ? (fs = true, btnFs.innerText = '退出全屏') : (fs = false, btnFs.innerText = '全屏观赏'));
})();
</script>

朵拉 发表于 2023-3-22 21:37

@马黑黑
马师 晚上好,学生又学习了一个,请指教{:4_190:}

马黑黑 发表于 2023-3-22 21:42

100√

小辣椒 发表于 2023-3-22 22:00

朵拉这个图图配的好{:4_199:}

朵拉 发表于 2023-3-22 23:01

小辣椒 发表于 2023-3-22 22:00
朵拉这个图图配的好

谢谢小辣椒欣赏,么么哒{:4_204:}

朵拉 发表于 2023-3-22 23:01

马黑黑 发表于 2023-3-22 21:42
100√

学生继续学习中~~{:4_190:}

马黑黑 发表于 2023-3-22 23:03

朵拉 发表于 2023-3-22 23:01
学生继续学习中~~

{:4_190:}

红影 发表于 2023-3-22 23:22

这个制作漂亮。欣赏朵宝好帖{:4_187:}

马黑黑 发表于 2023-3-24 12:12

布置朵朵买了电脑没
页: [1]
查看完整版本: 化身孤岛的鲸(马黑黑原创)