马黑黑 发表于 2022-9-17 19:26

关淑怡 - 忘记他

本帖最后由 马黑黑 于 2022-9-17 20:41 编辑 <br /><br /><style>
        #papa { left: -214px; width: 1024px; height: 640px; background: #ccc url('/data/attachment/forum/202209/17/192354ds48umk8khro44u4.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; bottom: 0; width: 300px; height: 80px; user-select: none; display: grid; place-items: center; cursor: pointer; }
        #mplayer:hover #btnwrap, #mplayer:hover #prog { transform: translateY(var(--yy)); }
        #mplayer:hover #btnwrap { background: linear-gradient(to top right, red, green); border-radius: 50%; opacity: .75; }
        #btnwrap, #prog { position: absolute; display: grid; place-items: center;transition: .5s; }
        #btnwrap { --yy: -15px; width: 40px; height: 40px; transform: rotate(45deg); border: 1px solid tan; border-radius: 6px; opacity: .25; }
        #btnplay { width: 20px; height: 20px; background: #eee; clip-path: polygon(0 0, 0% 100%, 100% 50%); }
        #btnpause { width: 2px; height: 20px; border-style: solid; border-width: 0px 4px; border-color: transparent #eee; display: none; }
        #prog { --yy: 20px; width: 300px; height: 16px; border-radius: 10px; background: linear-gradient(90deg, black, blue 100%, transparent 0); border: 1px solid gray; font: normal 14px / 16px sans-serif; color: olive; opacity: .75; }
        #lrc { position: absolute; right: 20px; top: 20px; font: bold 2em sans-serif; color: transparent; letter-spacing: 2px; background: linear-gradient(-90deg, purple, orange) 100% 100% / 200% 200%; background-clip: text; -webkit-background-clip: text; }
        #plane {position: absolute;left: 60px;top: 0;width: 100px;offset-distance: 0;offset-path: path("M0 20 Q300 80, 600 200 T1000 100");animation: move 8s linear infinite;}
        @keyframes bgMove1 { from { background-position: 0 0; } to { background-position: -100% 0; } }
        @keyframes bgMove2 { from { background-position: 0 0; } to { background-position: -100% 0; } }
        @keyframes move { to { offset-distance: 100%;} }
</style>

<div id="papa">
        <img id="plane" src="/data/attachment/forum/202209/17/192324pvmm0vvrnsds3yhd.png" alt="" />
        <div id="lrc">花潮lrc在线</div>
        <div id="mplayer">
                <div id="btnwrap"><span id="btnplay"></span><span id="btnpause"></span></div>
                <div id="prog">00:00 | 00:00</div>
        </div>
</div>

<script>
let lrcAr = [
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
];
let mKey = 0, mFlag = true;
let aud = new Audio();

aud.src = 'https://music.163.com/song/media/outer/url?id=68288.mp3';
aud.autoplay = true;
aud.loop = true;

btnwrap.onclick = () => aud.paused ? aud.play() : aud.pause();
prog.onclick = (e) => aud.currentTime = aud.duration * e.offsetX / prog.offsetWidth;
aud.addEventListener('pause', () => mState());
aud.addEventListener('play', () => mState());
aud.addEventListener('seeked', () => calcKey());

aud.addEventListener('timeupdate', () => {
        prog.style.background= 'linear-gradient(90deg, black, blue ' + aud.currentTime / aud.duration * 100 + '%, snow 0)';
        prog.innerText = toMin(aud.currentTime) + ' | ' + 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;
        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-17 19:30

本帖最后由 马黑黑 于 2022-9-17 20:41 编辑

代码分享
<style>
      #papa { left: -214px; width: 1024px; height: 640px; background: #ccc url('/data/attachment/forum/202209/17/192354ds48umk8khro44u4.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; bottom: 0; width: 300px; height: 80px; user-select: none; display: grid; place-items: center; cursor: pointer; }
      #mplayer:hover #btnwrap, #mplayer:hover #prog { transform: translateY(var(--yy)); }
      #mplayer:hover #btnwrap { background: linear-gradient(to top right, red, green); border-radius: 50%; opacity: .75; }
      #btnwrap, #prog { position: absolute; display: grid; place-items: center;transition: .5s; }
      #btnwrap { --yy: -15px; width: 40px; height: 40px; transform: rotate(45deg); border: 1px solid tan; border-radius: 6px; opacity: .25; }
      #btnplay { width: 20px; height: 20px; background: #eee; clip-path: polygon(0 0, 0% 100%, 100% 50%); }
      #btnpause { width: 2px; height: 20px; border-style: solid; border-width: 0px 4px; border-color: transparent #eee; display: none; }
      #prog { --yy: 20px; width: 300px; height: 16px; border-radius: 10px; background: linear-gradient(90deg, black, blue 100%, transparent 0); border: 1px solid gray; font: normal 14px / 16px sans-serif; color: olive; opacity: .75; }
      #lrc { position: absolute; right: 20px; top: 20px; font: bold 2em sans-serif; color: transparent; letter-spacing: 2px; background: linear-gradient(-90deg, purple, orange) 100% 100% / 200% 200%; background-clip: text; -webkit-background-clip: text; }
      #plane {position: absolute;left: 60px;top: 0;width: 100px;offset-distance: 0;offset-path: path("M0 20 Q300 80, 600 200 T1000 100");animation: move 8s linear infinite;}
      @keyframes bgMove1 { from { background-position: 0 0; } to { background-position: -100% 0; } }
      @keyframes bgMove2 { from { background-position: 0 0; } to { background-position: -100% 0; } }
      @keyframes move { to { offset-distance: 100%;} }
</style>

<div id="papa">
      <img id="plane" src="/data/attachment/forum/202209/17/192324pvmm0vvrnsds3yhd.png" alt="" />
      <div id="lrc">花潮lrc在线</div>
      <div id="mplayer">
                <div id="btnwrap"><span id="btnplay"></span><span id="btnpause"></span></div>
                <div id="prog">00:00 | 00:00</div>
      </div>
</div>

<script>
let lrcAr = [
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
      ,
];
let mKey = 0, mFlag = true;
let aud = new Audio();

aud.src = 'https://music.163.com/song/media/outer/url?id=68288.mp3';
aud.autoplay = true;
aud.loop = true;

btnwrap.onclick = () => aud.paused ? aud.play() : aud.pause();
prog.onclick = (e) => aud.currentTime = aud.duration * e.offsetX / prog.offsetWidth;
aud.addEventListener('pause', () => mState());
aud.addEventListener('play', () => mState());
aud.addEventListener('seeked', () => calcKey());

aud.addEventListener('timeupdate', () => {
      prog.style.background= 'linear-gradient(90deg, black, blue ' + aud.currentTime / aud.duration * 100 + '%, snow 0)';
      prog.innerText = toMin(aud.currentTime) + ' | ' + 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;
      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-17 19:35

本帖最后由 马黑黑 于 2022-9-17 19:36 编辑

纸飞机使用 offset-path 规划路线,使用CSS关键帧动画驱动,@keyframes move 即是,#plane 通过 animation 调用它。纸飞机完整代码提取:

一、CSS

#plane {
      position: absolute;
      left: 60px;
      top: 0;
      width: 100px;
      offset-distance: 0;
      offset-path: path("M0 20 Q300 80, 600 200 T1000 100");
      animation: move 8s linear infinite;
}

@keyframes move { to { offset-distance: 100%;} }

二、html

<img id="plane" src="/data/attachment/forum/202209/17/192324pvmm0vvrnsds3yhd.png" alt="" />



红影 发表于 2022-9-17 19:55

马黑黑 发表于 2022-9-17 19:35
纸飞机使用 offset-path 规划路线,使用CSS关键帧动画驱动,@keyframes move 即是,#plane 通过 animation...

路径里又出现个新的T呢,这个路径真漂亮{:4_199:}

红影 发表于 2022-9-17 19:56

现在这个的歌词同步差不多完美匹配到字了呢,很赞{:4_199:}

红影 发表于 2022-9-17 19:58

好像设置靠右,歌词就变成右对齐了,能否设置个歌词框,让歌词在自己的框里居中呢?

马黑黑 发表于 2022-9-17 20:21

红影 发表于 2022-9-17 19:55
路径里又出现个新的T呢,这个路径真漂亮

T 是偷懒的做法。当一个二次贝塞尔曲线设计出来后,用T引出最后的终点,整条线就是平滑过渡的

马黑黑 发表于 2022-9-17 20:21

红影 发表于 2022-9-17 19:56
现在这个的歌词同步差不多完美匹配到字了呢,很赞

还行还行

马黑黑 发表于 2022-9-17 20:22

红影 发表于 2022-9-17 19:58
好像设置靠右,歌词就变成右对齐了,能否设置个歌词框,让歌词在自己的框里居中呢?

可以,加个 width 和 height 便可

小辣椒 发表于 2022-9-17 20:29

黑黑我发现我完全理解错误了

马黑黑 发表于 2022-9-17 20:31

小辣椒 发表于 2022-9-17 20:29
黑黑我发现我完全理解错误了
是的,你好像读过博士似的,听不懂像俺这样的老百姓的大白话{:4_170:}

东篱闲人 发表于 2022-9-18 12:41

纸飞机够大。。。。{:5_116:}

马黑黑 发表于 2022-9-18 12:44

东篱闲人 发表于 2022-9-18 12:41
纸飞机够大。。。。

过得去

红影 发表于 2022-9-18 18:53

马黑黑 发表于 2022-9-17 20:21
T 是偷懒的做法。当一个二次贝塞尔曲线设计出来后,用T引出最后的终点,整条线就是平滑过渡的

哦哦,这个没用过。

红影 发表于 2022-9-18 18:57

马黑黑 发表于 2022-9-17 20:21
还行还行

这首歌也很喜欢的,在这个帖子里很享受。{:4_204:}

红影 发表于 2022-9-18 19:03

马黑黑 发表于 2022-9-17 20:22
可以,加个 width 和 height 便可

嗯嗯,好的,知道了{:4_187:}

马黑黑 发表于 2022-9-18 20:18

红影 发表于 2022-9-18 19:03
嗯嗯,好的,知道了

这好像是简单的问题额

马黑黑 发表于 2022-9-18 20:18

红影 发表于 2022-9-18 18:57
这首歌也很喜欢的,在这个帖子里很享受。

还是邓丽君唱的最好

马黑黑 发表于 2022-9-18 20:19

红影 发表于 2022-9-18 18:53
哦哦,这个没用过。

要去看文档的

红影 发表于 2022-9-18 20:43

马黑黑 发表于 2022-9-18 20:18
这好像是简单的问题额

说明我学习得不扎实啊{:4_173:}
页: [1] 2 3
查看完整版本: 关淑怡 - 忘记他