红影 发表于 2022-9-21 21:28

望故乡(学习黑黑LRC歌词同步微调)

<style>
        #papa { left: -302px; width: 1200px; height: 675px; background: #ccc url('https://pic.imgdb.cn/item/6329c5aa16f2c2beb111024f.jpg') no-repeat center/cover; box-shadow: 3px 3px 20px #000; display: grid; place-items: center; overflow: hidden; position: relative; z-index: 1; }
        #mplayer { position: absolute; right: 60px; bottom: 30px; }
        #btnwrap { fill: snow; cursor: pointer; }
        #btnwrap:hover { fill: olive; }
        #tmsg { fill: snow; stroke: gray; stroke-width: 1px; font: bold 1em sans-serif; }
        #lrc { position: absolute; bottom: 250px; left: 680px; font: bold 2em sans-serif; color: transparent; letter-spacing: 2px; background: linear-gradient(-90deg, darkgreen, orange, tomato) 100% 100% / 200% 200%; background-clip: text; -webkit-background-clip: text; }
        #hudie { position: absolute; left: 50px; top: 30px; }
.mazha { position: absolute; left: 400px; top: 0; width: 100px; transform: rotate(220deg); offset-distance: 0; offset-path: path("M250 250 Q140 220, 130 390 Q20 360, 10 530 Q-100 500, -110 670"); animation: move 4s linear infinite; }
@keyframes move { to { offset-distance: 100%;} }
        @keyframes bgMove1 { from { background-position: 0 0; } to { background-position: -100% 0; } }
        @keyframes bgMove2 { from { background-position: 0 0; } to { background-position: -100% 0; } }
</style>

<div id="papa">
      <img class="mazha" src="https://pic.imgdb.cn/item/6329d46b16f2c2beb1227d6f.png" alt="" />
        <img id="hudie" src="https://pic.imgdb.cn/item/62a09aa50947543129666cf8.gif" alt="" />
        <div id="lrc">花潮lrc在线</div>
        <svg id="mplayer" width="120" height="120">
                <g id="mama" transform="rotate(-90, 60, 60)" style="cursor: pointer">
                        <circle id="track" cx="60" cy="60" r="50" fill="none" stroke-width="10" stroke="rgba(255,255,255,0.65)" />
                        <circle id="prog" cx="60" cy="60" r="50" fill="none" stroke-width="6" stroke="rgba(57,54,81,0.85)" />
                </g>
                <g id="btnwrap">
                        <path id="btnplay" d="M 50 50,50 70,70, 60 z"></path>
                        <path id="btnpause" d="M 52 50,52 70,57 70,57 50,52 50 z M 60 50,60 70,65 70,65 50,60 50 z" style="display:none"></path>
                        <path d="M 57 50,60 50,60 70,57 70 z" fill="transparent" />
                </g>
                <path id="curPath" d="M 20 70 Q 60 0 100 70" fill="none" stroke="none"/>
                <path id="durPath" d="M 20 55 Q 60 110 100 55" fill="none" stroke="none"/>
                <g id="tmsg">
                        <text x="34" y="0"><textPath id="curMsg" xlink:href="#curPath" dominant-baseline="text-after-edge">00:00</textPath></text>
                        <text x="29" y="0"><textPath id="durMsg" xlink:href="#durPath" dominant-baseline="text-before-edge">00:00</textPath></text>
                </g>
        </svg>
</div>

<script>
let lrcAr = [
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
       
];
let mKey = 0, mFlag = true, aud = new Audio();
let cc = {
        x: 1*track.getAttribute('cx'),
        y: 1*track.getAttribute('cy'),
        r: 1*track.getAttribute('r'),
        len: track.getTotalLength(),
};

prog.style.strokeDasharray = prog.style.strokeDashoffset =cc.len;
aud.src = 'https://music.163.com/song/media/outer/url?id=322035.mp3';
aud.autoplay = true;
aud.loop = true;

mama.onclick = (e) => {
        let deg = Math.atan2(e.offsetY - cc.y, e.offsetX - cc.x) * 180 / Math.PI;
        deg += (e.offsetX < cc.x && e.offsetY < cc.y) ? 450 : 90;
        aud.currentTime = aud.duration * deg / 360;
};

btnwrap.onclick = () => aud.paused ? aud.play() : aud.pause();

aud.addEventListener('pause', () => mState());
aud.addEventListener('play', () => mState());
aud.addEventListener('seeked', () => calcKey());

aud.addEventListener('timeupdate', () => {
        prog.style.strokeDashoffset = cc.len - cc.len * aud.currentTime / aud.duration;
        curMsg.textContent = toMin(aud.currentTime);
        durMsg.textContent = toMin(aud.duration);
        for(j=0; j<lrcAr.length; j++) {
                if(aud.currentTime >= lrcAr) {
                        if(mKey === j) showLrc(lrcAr);
                        else continue;
                }
        }
});

let mState = () => aud.paused ? (btnplay.style.display = 'block', btnpause.style.display = 'none',
lrc.style.animationPlayState = 'paused') : (btnplay.style.display = 'none', btnpause.style.display = 'block',
lrc.style.animationPlayState = 'running');

let showLrc = (time) => {
        lrc.style.animation = (mFlag ? 'bgMove1 ' : 'bgMove2 ') + time + 's linear forwards';
        lrc.innerHTML = lrcAr;
        mKey += 1;
        mFlag = !mFlag;
}

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 mtime = lrcAr - (aud.currentTime - lrcAr);
        showLrc(mtime);
}

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;
}

</script>

红影 发表于 2022-9-21 21:32

那个微调很棒,能让歌词同步更准确。
试着弄个蚂蚱路径,分了三段让它跳{:4_173:}

加林森 发表于 2022-9-21 21:38

制作漂亮。赞!

绿叶清舟 发表于 2022-9-21 21:38

现在的歌词很精准了啊

马黑黑 发表于 2022-9-21 21:45

蚂蚱会三级跳,厉害哈

马黑黑 发表于 2022-9-21 21:46

歌词同步的微调很到位,太赞了

小辣椒 发表于 2022-9-21 21:49

亲爱的,这个歌词同步颜色修改的漂亮{:4_199:}

醉美水芙蓉 发表于 2022-9-22 07:00

马黑黑 发表于 2022-9-22 07:24

{:4_199:}

梦油 发表于 2022-9-22 09:14

两只蝴蝶的颜色搭配的真好,给整个画面增添了生气。

红影 发表于 2022-9-22 10:47

加林森 发表于 2022-9-21 21:38
制作漂亮。赞!

谢谢队长鼓励,这个也是套用呢{:4_173:}

红影 发表于 2022-9-22 10:49

绿叶清舟 发表于 2022-9-21 21:38
现在的歌词很精准了啊

黑黑弄了个新的微调制作帖子,到那里面就能做出更准确的歌词了{:4_173:}

红影 发表于 2022-9-22 10:51

马黑黑 发表于 2022-9-21 21:45
蚂蚱会三级跳,厉害哈

我实在吃不准T的效果,弄了3个Q的效果,好在是45度方向的取值,仍然可以平分各段,若是其他角度就比较难分了。{:4_173:}

红影 发表于 2022-9-22 10:51

马黑黑 发表于 2022-9-21 21:46
歌词同步的微调很到位,太赞了

应该谢谢黑黑的那个微调帖子,那个取到小数点后一位的设计太准确了{:4_187:}

红影 发表于 2022-9-22 10:52

小辣椒 发表于 2022-9-21 21:49
亲爱的,这个歌词同步颜色修改的漂亮

歌词颜色就是黑黑原来的,我直接套用的,唯一花点心思的是那只蚂蚱的路径{:4_173:}

红影 发表于 2022-9-22 10:53

醉美水芙蓉 发表于 2022-9-22 07:00
红影厉害做得更漂亮!

谢谢水芙蓉美女鼓励{:4_187:}

红影 发表于 2022-9-22 10:54

梦油 发表于 2022-9-22 09:14
两只蝴蝶的颜色搭配的真好,给整个画面增添了生气。

那俩小蝴蝶是以前上传的,就直接拿来用了{:4_173:}

马黑黑 发表于 2022-9-22 12:10

红影 发表于 2022-9-22 10:51
应该谢谢黑黑的那个微调帖子,那个取到小数点后一位的设计太准确了

也要手巧的才行

马黑黑 发表于 2022-9-22 12:11

红影 发表于 2022-9-22 10:51
我实在吃不准T的效果,弄了3个Q的效果,好在是45度方向的取值,仍然可以平分各段,若是其他角度就比较难 ...

曲线的线外控制点是关键吧

红影 发表于 2022-9-22 12:41

马黑黑 发表于 2022-9-22 12:11
曲线的线外控制点是关键吧

噩梦,线外控制点决定了曲线的凸起是多点还是少点。这点仍然可以均匀分布,让三段是相似的。
页: [1] 2 3 4 5
查看完整版本: 望故乡(学习黑黑LRC歌词同步微调)