马黑黑 发表于 2025-7-13 12:49

Amernan - Matsuri

<style>
    #papa { margin: 30px 0; left: calc(50% - 81px); transform: translateX(-50%); width: clamp(600px, 90vw, 1400px); height: auto; aspect-ratio: 16/9; background: url('https://638183.freep.cn/638183/t24/6/matsuri.jpg') no-repeat center/cover; box-shadow: 2px 2px 8px #000; z-index: 1; overflow: hidden; display: grid; place-items: center; position: relative; --r: 2vw; --size: 10vw; }
    #btnFs { left: 15px; bottom: 20px; color: white; }
    #ball { position: absolute; width: var(--size); height: var(--size); background: url('https://638183.freep.cn/638183/t23/1/rabbit.gif') no-repeat center/cover; border-radius: 50%; filter: drop-shadow(10px 10px 40px #eee); cursor: pointer; display: grid; place-items: center; }
    #ball::before, #ball::after { position: absolute; content: ''; width: 120%; height: 120%; background: linear-gradient(35deg, skyblue, lightgreen); border-radius: 100% 50%; transition: 1s; transform-origin: 50% 97%; }
    #ball::before { clip-path: inset(0 50% 0 0); transform: rotate(var(--a1)); z-index: 90; }
    #ball::after { clip-path: inset(0 0 0 50%); transform: translate(-1px) rotate(var(--a2)); }
    #lzwrap { position: absolute; display: grid; place-items: center; }
    li-zi { position: absolute; width: 50px; height: 50px; border-radius: 50%; background: linear-gradient(35deg, var(--c1), var(--c2)); transform: rotate(var(--deg)) translate(var(--r)); transition: 0.65s; }
    #vid {position: absolute; width: 100%; height: 100%; object-fit: cover; mask: radial-gradient(transparent 20%, red); -webkit-mask: radial-gradient(transparent 20%, red); opacity: .35; pointer-events: none; }
    .run { animation: run 12s linear infinite; }
    @keyframes run { to { transform: rotate(360deg); } }
</style>

<div id="papa">
    <audio id="aud" src="https://music.163.com/song/media/outer/url?id=1066047" autoplay loop></audio>
    <video id="vid" src="https://bpic.588ku.com/video_listen/588ku_video/24/10/07/13/54/42/video670377a269c9e.mp4" autoplay loop muted></video>
    <div id="ball">
      <div id="lzwrap"></div>
    </div>
</div>

<script type="module">
    import { FS } from 'https://638183.freep.cn/638183/web/js/fullscreen.js';
    var total = 12;
    Array.from({ length: total }).forEach( (lz, idx) => {
      lz = document.createElement('li-zi');
      lz.style.cssText += `
            --c1: #${Math.random().toString(16).substring(2, 8)};
            --c2: #${Math.random().toString(16).substring(2, 8)};
            --deg: ${-idx * 360 / total}deg;
      `;
      lzwrap.appendChild(lz);
    });
    var init = () => {
      var r = 15 * papa.clientWidth / 1400,
            s = 10 * papa.clientWidth / 1400;
      papa.style.cssText += `
            --size: ${s}vw;
            --r: ${aud.paused ? 0 : r}vw;
            --a1: ${aud.paused ? 0 : -60}deg;
            --a2: ${aud.paused ? 0 : 60}deg;
      `;
    };
    var animate = () => aud.paused ? lzwrap.classList.remove('run') : lzwrap.classList.add('run');
    aud.onplaying = aud.onpause = () => {
      init();
      animate();
    };
    window.onresize = () => init();
    FS(papa, ball);
</script>

马黑黑 发表于 2025-7-13 12:50

帖子代码:
<style>
    #papa { margin: 30px 0; left: calc(50% - 81px); transform: translateX(-50%); width: clamp(600px, 90vw, 1400px); height: auto; aspect-ratio: 16/9; background: url('https://638183.freep.cn/638183/t24/6/matsuri.jpg') no-repeat center/cover; box-shadow: 2px 2px 8px #000; z-index: 1; overflow: hidden; display: grid; place-items: center; position: relative; --r: 2vw; --size: 10vw; }
    #btnFs { left: 15px; bottom: 20px; color: white; }
    #ball { position: absolute; width: var(--size); height: var(--size); background: url('https://638183.freep.cn/638183/t23/1/rabbit.gif') no-repeat center/cover; border-radius: 50%; filter: drop-shadow(10px 10px 40px #eee); cursor: pointer; display: grid; place-items: center; }
    #ball::before, #ball::after { position: absolute; content: ''; width: 120%; height: 120%; background: linear-gradient(35deg, skyblue, lightgreen); border-radius: 100% 50%; transition: 1s; transform-origin: 50% 97%; }
    #ball::before { clip-path: inset(0 50% 0 0); transform: rotate(var(--a1)); z-index: 90; }
    #ball::after { clip-path: inset(0 0 0 50%); transform: translate(-1px) rotate(var(--a2)); }
    #lzwrap { position: absolute; display: grid; place-items: center; }
    li-zi { position: absolute; width: 50px; height: 50px; border-radius: 50%; background: linear-gradient(35deg, var(--c1), var(--c2)); transform: rotate(var(--deg)) translate(var(--r)); transition: 0.65s; }
    #vid {position: absolute; width: 100%; height: 100%; object-fit: cover; mask: radial-gradient(transparent 20%, red); -webkit-mask: radial-gradient(transparent 20%, red); opacity: .35; pointer-events: none; }
    .run { animation: run 12s linear infinite; }
    @keyframes run { to { transform: rotate(360deg); } }
</style>

<div id="papa">
    <audio id="aud" src="https://music.163.com/song/media/outer/url?id=1066047" autoplay loop></audio>
    <video id="vid" src="https://bpic.588ku.com/video_listen/588ku_video/24/10/07/13/54/42/video670377a269c9e.mp4" autoplay loop muted></video>
    <div id="ball">
      <div id="lzwrap"></div>
    </div>
</div>

<script type="module">
    import { FS } from 'https://638183.freep.cn/638183/web/js/fullscreen.js';
    var total = 12;
    Array.from({ length: total }).forEach( (lz, idx) => {
      lz = document.createElement('li-zi');
      lz.style.cssText += `
            --c1: #${Math.random().toString(16).substring(2, 8)};
            --c2: #${Math.random().toString(16).substring(2, 8)};
            --deg: ${-idx * 360 / total}deg;
      `;
      lzwrap.appendChild(lz);
    });
    var init = () => {
      var r = 15 * papa.clientWidth / 1400,
            s = 10 * papa.clientWidth / 1400;
      papa.style.cssText += `
            --size: ${s}vw;
            --r: ${aud.paused ? 0 : r}vw;
            --a1: ${aud.paused ? 0 : -60}deg;
            --a2: ${aud.paused ? 0 : 60}deg;
      `;
    };
    var animate = () => aud.paused ? lzwrap.classList.remove('run') : lzwrap.classList.add('run');
    aud.onplaying = aud.onpause = () => {
      init();
      animate();
    };
    window.onresize = () => init();
    FS(papa, ball);
</script>

马黑黑 发表于 2025-7-13 12:51

本帖最后由 马黑黑 于 2025-7-13 17:54 编辑

代码说明:


《Matsuri》代码解析 - 马黑黑教程专版 - 花潮论坛 - Powered by Discuz!

杨帆 发表于 2025-7-13 14:19

奇妙的构思,巧妙的实现,完美的效果

谢谢马老师经典讲授与示范{:4_190:}

红影 发表于 2025-7-13 15:11

这个好,不但有金球藏娇效果的运用,还有粒子小球的收发自如。
视频的烟花也和背景烟花好相似啊{:4_199:}

红影 发表于 2025-7-13 15:12

马黑黑 发表于 2025-7-13 12:51
代码说明:




我赶紧先去看代码说明去,嗖~~~

马黑黑 发表于 2025-7-13 18:06

红影 发表于 2025-7-13 15:12
我赶紧先去看代码说明去,嗖~~~

{:4_190:}

马黑黑 发表于 2025-7-13 18:06

红影 发表于 2025-7-13 15:11
这个好,不但有金球藏娇效果的运用,还有粒子小球的收发自如。
视频的烟花也和背景烟花好相似啊

这个可以选

马黑黑 发表于 2025-7-13 18:06

杨帆 发表于 2025-7-13 14:19
奇妙的构思,巧妙的实现,完美的效果

谢谢马老师经典讲授与示范

这个应该是很简单的,希望能理解全部代码

杨帆 发表于 2025-7-13 18:14

马黑黑 发表于 2025-7-13 18:06
这个应该是很简单的,希望能理解全部代码

谢谢老师,还不能完全看懂呢,慢慢跟老师学习吧{:4_190:}

马黑黑 发表于 2025-7-13 18:36

杨帆 发表于 2025-7-13 18:14
谢谢老师,还不能完全看懂呢,慢慢跟老师学习吧

理解是创作的基础

杨帆 发表于 2025-7-13 19:02

马黑黑 发表于 2025-7-13 18:36
理解是创作的基础

是,还谈不上创作呢,是从零起步跟老师慢慢学的,感恩{:4_190:}

马黑黑 发表于 2025-7-13 19:44

杨帆 发表于 2025-7-13 19:02
是,还谈不上创作呢,是从零起步跟老师慢慢学的,感恩

有时间过一遍 CSS、HTML、JS,再根据情况决定是否扩展:

https://www.runoob.com/

杨帆 发表于 2025-7-13 19:47

马黑黑 发表于 2025-7-13 19:44
有时间过一遍 CSS、HTML、JS,再根据情况决定是否扩展:

https://www.runoob.com/

好的,感恩老师{:4_190:}

红影 发表于 2025-7-13 21:37

马黑黑 发表于 2025-7-13 18:06


谢谢黑黑,辛苦了{:4_187:}

马黑黑 发表于 2025-7-13 21:38

红影 发表于 2025-7-13 21:37
谢谢黑黑,辛苦了

谢谢

马黑黑 发表于 2025-7-13 21:40

杨帆 发表于 2025-7-13 19:47
好的,感恩老师

恩师谈不上,老师也未必讲得通。都是朋友。

红影 发表于 2025-7-13 21:40

马黑黑 发表于 2025-7-13 18:06
这个可以选

这个里面的选得很好呢{:4_187:}

马黑黑 发表于 2025-7-13 21:47

红影 发表于 2025-7-13 21:40
这个里面的选得很好呢

闭上眼睛都能选的

红影 发表于 2025-7-13 22:58

马黑黑 发表于 2025-7-13 21:47
闭上眼睛都能选的

睁着眼的选不是更好么{:4_173:}
页: [1] 2 3
查看完整版本: Amernan - Matsuri