红影 发表于 2023-5-12 22:06

《纸船》学习黑黑css-doodle代码

<style>
#papa {margin: 80px 0 0 calc(50% - 593px);width: 1024px;height: 640px;background: tan url('https://pic2.imgdb.cn/item/645e36590d2dde5777b9b3a1.jpg');box-shadow: 0 0 8px #000;display: grid;place-items: center;position: relative;--state: paused;}
css-doodle{position: absolute;}
</style>

<div id="papa">
        <css-doodle id="mplayer">
                :doodle {
                        @grid: 2 / 600px 100px;
                        color: var(--color);
                        bottom: 24px;
                        z-index: 100;
                        --prog: 0%; --size: 40px; --ttmsg1: '00:00'; --ttmsg2: '00:00'; --color: LightPink;
                }
                /* 时间信息 : 左 */
                @nth(1) {
                        @place: 15% 100%;
                        :after { content: var(--ttmsg1); }
                }
                /* 控制器 */
                @nth(2) {
                        @size: 60px;
                        @shape: windmill;
                        @place: 50% 35%;                        
                        background: var(--color);
                        animation: rot 6s infinite linear var(--state);
                }
                /* 时间信息 : 右 */
                @nth(3) {
                        @place: 85% 100%;
                        :after { content: var(--ttmsg2); }
                }
                /* 进度条 */
                @nth(4) {
                        @place: 50% 80%;
                        @size: 100% 2px;
                        background: snow;
                        display: grid;
                        place-items: center start;
                        :before {
                                content: '';
                                width: var(--prog);
                                height: 100%;
                                background: var(--color);
                        }
                }
                @keyframes rot { to { transform: rotate(1turn); } }
        </css-doodle>
        <css-doodle id="lrc">
                :doodle {
                        @size: auto 4em;
                        top: 20px;
                        --geci: "花潮lrc在线"; --motion: cover2; --tt: 1s;
                }
                /* 单元格两个伪元素显示lrc歌词 */
                display: grid;
                place-items: center start;
                :before, :after {
                        content: var(--geci);
                        color: snow; /* 歌词底色 */
                        font: bold 2em sans-serif;
                        text-shadow: 1px 1px 2px #000;
                        white-space: pre;
               }
                :after {
                        position: absolute;
                        width: 0;
                        color: LightPink; /* 同步歌词颜色 */
                        overflow: hidden;
                        animation: var(--motion) var(--tt) linear forwards var(--state);
                }
                @keyframes cover1 { from { width: 0; } to { width: 100%; } }
                @keyframes cover2 { from { width: 0; } to { width: 100%; } }
        </css-doodle>
<css-doodle grid="16" id="fFloat">
        :doodle {
                @size: 1024px 640px;
                --state:paused;
        }
        position: absolute;
        left: @r(-105)%;
        top: 10%;
        :after {
                position: absolute;
                content: '@p(♪,¶,♫,♯,♭,♮,♩,♬,☺,❀)';
                color:LightSkyBlue;
                font-size: @r(8, 30)px;
        }
        animation: fall 40s @r(-6, 36)s infinite var(--state);
        @keyframes fall {
                from { transform: rotate(0deg) translate(0px); }
                to { transform: rotate(@r(-60,60)deg) translate(1500px); }
        }
</css-doodle>
        <audio id="aud" src="https://music.163.com/song/media/outer/url?id=1393207313.mp3" autoplay loop></audio>
</div>

<script>
(function() {
        let script = document.createElement('script');
        script.src = 'https://unpkg.com/css-doodle@0.34.9/css-doodle.min.js';
        document.head.appendChild(script);
        let slip = 0.5, mFlag = true, mKey = 0, clickIdx = 0, progChg = 0, cursors = ['default','pointer','pointer'];
        let lrcAr = [
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
       
];
        let toMin = (val) => {if (!val) return '00:00';val = Math.floor(val);let min = parseInt(val / 60), sec = parseFloat(val % 60);if (min < 10) min = '0' + min;if (sec < 10) sec = '0' + sec;return min + ':' + sec;};
        let calcKey = () => {for (j = 0;j < lrcAr.length;j++) {if (aud.currentTime <= lrcAr) {mKey = j - 1;break;}}if (mKey < 0) mKey = 0;if (mKey > lrcAr.length - 1) mKey = lrcAr.length - 1;let time = lrcAr - (aud.currentTime - lrcAr);showLrc(time);};
        let mState = () => aud.paused ? (papa.style.setProperty('--state', 'paused'),fFloat.style.setProperty('--state', 'paused') ) : (papa.style.setProperty('--state','running'),fFloat.style.setProperty('--state', 'running'));
        let showLrc = (time) => {lrc.style.setProperty('--motion', mFlag ? 'cover1' : 'cover2');lrc.style.setProperty('--geci', '"' + lrcAr + '"');lrc.style.setProperty('--tt', time + 's');mKey += 1;mFlag = !mFlag;};
        aud.addEventListener('play', mState, false);
        aud.addEventListener('pause', mState, false);
        aud.addEventListener('seeked', () => calcKey());
        aud.addEventListener('timeupdate', () => {for (j = 0; j < lrcAr.length; j++) {if (aud.currentTime - slip >= lrcAr) {cKey = j;if (mKey === j) showLrc(lrcAr);else continue;}}mplayer.style.setProperty('--ttmsg1', `'${toMin(aud.currentTime)}'`);mplayer.style.setProperty('--ttmsg2', `'${toMin(aud.duration)}'`);mplayer.style.setProperty('--prog',`${100 * aud.currentTime / aud.duration}%`);});
        mplayer.onclick = () => {if(clickIdx === 1) aud.paused ? aud.play() : aud.pause();if(clickIdx === 2) aud.currentTime = progChg;};
        mplayer.onmousemove = (e) => {let size = parseInt(window.getComputedStyle(mplayer).getPropertyValue('--size')), ww = mplayer.offsetWidth, hh = mplayer.offsetHeight;clickIdx = e.offsetY > hh/1.5 ? 2 : (e.offsetX > (ww - size)/2 && e.offsetX < (ww + size)/2 && e.offsetY < hh/1.5 ? 1 : 0);mplayer.style.cursor = cursors;if(clickIdx > 1) progChg = aud.duration * e.offsetX / ww;};
})();
</script>

红影 发表于 2023-5-12 22:07

也跟着学做个,为了做帖子,论坛的提醒都没来得及回复。{:4_173:}
感谢@马黑黑的代码{:4_187:}

红影 发表于 2023-5-12 22:08

同时也感谢@亦是金和@起个网名好难两位老师,帖子里也借鉴了你们的代码{:4_187:}

小辣椒 发表于 2023-5-12 22:08

亲爱的做的好美{:4_199:}

小辣椒 发表于 2023-5-12 22:09

我今天没有电脑,争取明天学习做一次

马黑黑 发表于 2023-5-12 22:18

有创意,色彩运用的也很好

起个网名好难 发表于 2023-5-12 22:47

你这更高级,完全是css-doodle代码了, 大赞!

亦是金 发表于 2023-5-12 22:48

问好红影,欣赏你的美帖,歌曲,背景,动画协调!收藏欣赏学习了!{:4_187:}

红影 发表于 2023-5-12 22:50

小辣椒 发表于 2023-5-12 22:08
亲爱的做的好美

亲爱的,你这个回复得真快,发出来没多久你就回复了{:4_173:}

红影 发表于 2023-5-12 22:51

小辣椒 发表于 2023-5-12 22:09
我今天没有电脑,争取明天学习做一次

嗯,这个黑黑的最新代码还是很有趣的。

红影 发表于 2023-5-12 22:52

马黑黑 发表于 2023-5-12 22:18
有创意,色彩运用的也很好

我把那个进度条也拉长了一点。颜色也懒得配了,就都取一样的了{:4_173:}

马黑黑 发表于 2023-5-12 22:52

红影 发表于 2023-5-12 22:52
我把那个进度条也拉长了一点。颜色也懒得配了,就都取一样的了

效果挺好的

红影 发表于 2023-5-12 22:52

起个网名好难 发表于 2023-5-12 22:47
你这更高级,完全是css-doodle代码了, 大赞!

把您的那个最新制作的帖子也取了一段放进帖子了,谢谢难难{:4_187:}

红影 发表于 2023-5-12 22:53

亦是金 发表于 2023-5-12 22:48
问好红影,欣赏你的美帖,歌曲,背景,动画协调!收藏欣赏学习了!

谢谢亦是金,学了你的横向飘飞的花朵。感谢你的代码{:4_187:}

起个网名好难 发表于 2023-5-12 23:05

红影 发表于 2023-5-12 22:52
把您的那个最新制作的帖子也取了一段放进帖子了,谢谢难难

三个css-doodle段 按 fFloat、lrc、mplayer 的顺序就用不着设置z-index: 100;

千羽 发表于 2023-5-12 23:07

影儿,我今晚看图都很困难啊,看黑黑老师的也是这样的{:4_203:}

千羽 发表于 2023-5-12 23:08

回帖也是很卡

醉美水芙蓉 发表于 2023-5-12 23:57

小文 发表于 2023-5-13 07:47

太厉害了,又美又漂亮,不知道说什么好啦,哈哈!{:4_170:}

亦是金 发表于 2023-5-13 08:34

本帖最后由 亦是金 于 2023-5-13 08:41 编辑

红影 发表于 2023-5-12 22:53
谢谢亦是金,学了你的横向飘飞的花朵。感谢你的代码
@红影问好红影!{:4_187:}我没有原创的代码。横向飘飞的花朵是应用了朵拉\芙蓉雨帖子的代码,我只是调整了飞花起点位置而已!{:5_111:}
页: [1] 2 3
查看完整版本: 《纸船》学习黑黑css-doodle代码