亚伦影音工作室 发表于 2023-5-14 22:16

找一个笑着流泪的借口

本帖最后由 亚伦影音工作室 于 2023-5-15 07:07 编辑 <br /><br /><style>
#papa {
        margin: 120px -300px;
        width: 1164px;
        height: 640px;
        box-shadow: 1px 1px 1px #000;
background:lightgreenurl('https://img-baofun.zhhainiao.com/fs/scene/preview_img_raw/663bf23e7639740c41045affdbb1ea27_preview_raw.jpg')no-repeat center/cover;
        position: relative;
        display: grid;
        place-items: center;
        z-index: 1;
}
css-doodle { position: absolute; }
#canv {filter:hue-rotate(10deg)contrast(140%)brightness(100%);
        position: absolute;
        display: block;
        height: 100%;
        position: relative;
        cursor: pointer;
        z-index: 2;
}
#vid { display: none; }

.wenzi { position: absolute; left: 74%; top: 11%; z-index: 4; color:#cccccc; font: bold 20px/20px 'FangSong',serif;opacity: .8; }

#papa:hover #fullscreen { display:block ;}

#fullscreen { position: absolute; top:4%; left:3%;color:#FFffff; filter:drop-shadow( 1px 1px 1px #000000);font: normal 2emFangSong; opacity: 1; cursor: pointer; z-index: 4}
</style>

<div id="papa">
<span id="fullscreen">全屏观赏</span>
        <canvas id="canv"></canvas>
        <css-doodle grid="6" id="mypic">
          :doodle { top:2%; left:70%;
                @grid: 2 / 300px 60px;
                position: absolute;z-index: 8;
                color: var(--color);
            transform: scale(1);
                --prog: 0%; --size: 40px; --ttmsg1: '00:00'; --ttmsg2: '00:00'; --color:#ffffff; --state: paused;
      }
      /* 时间信息 : 左 */
      @nth(1) {
                @place: 10% 125%;
                :after { content: var(--ttmsg1); }
      }
      /* 控制器 */
      @nth(2) { position: absolute;z-index: 10;
                @size: var(--size);
            @shape: windmill;
                @place: 50% 35%;
            
                background: var(--color);
                animation: rot 6s infinite linear var(--state);
      }
      /* 时间信息 : 右 */
      @nth(3) {
                @place: 90% 125%;
                :after { content: var(--ttmsg2); }
      }
      /* 进度条 */
      @nth(4) {
                @place: 50% 80%;
                @size: 60% 2px;
                background: #aaaaaa;
               display: grid;
                place-items: center start;
                :before {
                        content: '';
                        width: var(--prog);
                        height: 60%;
                        background: var(--color);
                }
      }
      @keyframes rot { to { transform: rotate(1turn); } }
        </css-doodle>
        <video id="vid" src="http://chuangshicdn.data.mvbox.cn/music/yc/21/09/27/21092708394423902689.mp4" autoplay loop muted></video>
        <div class="wenzi">找一个笑着流泪的借口</div>

<div data-lrc="亚伦影音工作室" id="lrc">亚伦影音工作室</div>

</div>

<audio id="aud" src="https://www.qqmc.com/mp3/music274669134.mp3" autoplay loop></audio>
<script>



(function() {
      let clickIdx = 0, progChg = 0, cursors = ['default','pointer','pointer'];
      let script = document.createElement('script');
      script.src = 'https://638183.freep.cn/638183/web/api/css-doodle.js';
      document.head.appendChild(script);
      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 mState = () => mypic.style.setProperty('--state', aud.paused ? 'paused' : 'running');
      aud.addEventListener('play', mState, false);
      aud.addEventListener('pause', mState, false);
      aud.addEventListener('timeupdate', () => {
               mypic.style.setProperty('--ttmsg1', `'${toMin(aud.currentTime)}'`);
                mypic.style.setProperty('--ttmsg2', `'${toMin(aud.duration)}'`);
               mypic.style.setProperty('--prog',`${100 * aud.currentTime / aud.duration}%`)
      });


})();




let ctx = canv.getContext('2d');
let ww = canv.width = papa.offsetWidth, hh = canv.height = papa.offsetHeight;
let loop = () => {
        ctx.drawImage(vid, 0, 0, ww, hh);
        if(!vid.paused) {
                requestAnimationFrame(loop);
                return;
        }
}
let mState = () => aud.paused ? (mypic.style.setProperty('--state', 'paused'), vid.pause()) : (mypic.style.setProperty('--state', 'running'), vid.play());
vid.addEventListener('play', loop, false);
aud.addEventListener('play', () => mState());
aud.addEventListener('pause', () => mState());
mypic.addEventListener('click', () => aud.paused ? aud.play() : aud.pause());
</script>

<style type="text/css">#lrc {
        --state: paused;
        --motion: cover2;
        --tt: 2s;
        --bg: linear-gradient(180deg, #880000, #880000);
        position: absolute;z-index: 40;
        left: 50%;
        transform: translate(-50%);
        top: 85%;
        font:normal 3em 华文隶书;
        color: #000078;
        white-space: pre;
        -webkit-background-clip: text;
        filter:drop-shadow(#FFFFFF 1px 0 0)drop-shadow(#FFFFFF 0 1px 0)drop-shadow(#FFFFFF -1px 0 0) drop-shadow(#FFFFFF 0 -1px0);
}
#lrc::before {
        position: absolute;
        content: attr(data-lrc);
        width: 20%;
        height: 100%;
        color: transparent;
        overflow: hidden;
        white-space: pre;
        background: var(--bg);
       
        -webkit-background-clip: text;
        animation: var(--motion) var(--tt) linear forwards;
        animation-play-state: var(--state);
}
@keyframes cover1 { from { width: 0; } to { width: 100%; } }
@keyframes cover2 { from { width: 0; } to { width: 100%; } }
</style>
<script >
(function() {
/*原始lrc歌词*/
let lrcStr = `
找一个笑着流泪的借口 - 李英
词:周洪/赵润泽
曲:赵润泽
原唱:李英
录音:可心文化娱乐工作室
编混:可心文化娱乐工作室
制作人:赵润泽
监制:赵润泽
出品:亚伦影音工作室
说过的承诺能撑多久
身上的香水早已把你暴露
说我比不上那些红花绿柳
早知不长久应该有所保留
爱了能否一辈子拥有
衣领上口红让你像个小丑
最初的相拥抵不过一句分手
是不是我哪里做的不够
找一个笑着流泪的借口
庆幸我已把你的心看透
收起你那虚伪假装的温柔
无法挽留就放爱自由
找一个笑着流泪的借口
幻想的爱总比现实要长久
当缘分到了尽头各奔东西后
记得曾经彼此的拥有
爱了能否一辈子拥有
衣领上口红让你像个小丑
最初的相拥抵不过一句分手
是不是我哪里做的不够
找一个笑着流泪的借口
庆幸我已把你的心看透
收起你那虚伪假装的温柔
无法挽留就放爱自由
找一个笑着流泪的借口
幻想的爱总比现实要长久
当缘分到了尽头各奔东西后
记得曾经彼此的拥有
找一个笑着流泪的借口
庆幸我已把你的心看透
收起你那虚伪假装的温柔
无法挽留就放爱自由
找一个笑着流泪的借口
幻想的爱总比现实要长久
当缘分到了尽头各奔东西后
记得曾经彼此的拥有
`;

/*变量 :mKey - 当前歌词索引;mFlag :调用关键帧动画索引;averAdd :平均值补偿*/
let mKey = 0, mFlag = true, averAdd = 0.3;

/*函数 :获取每句歌词用时,歌词用时若超过平均值则取平均值,最后一句歌词则取平均值*/
let lrcTime = (ar) => {
        let tmpAr = [];
        for(j = 0; j <ar.length - 1; j ++) {
                if(j !== ar.length - 1) tmpAr = parseFloat((ar - ar).toFixed(1));
        }
        let aver = parseInt(tmpAr.reduce((a,b) => a + b) / (tmpAr.length - 1)) + averAdd;
        tmpAr.push(aver);
        tmpAr.forEach((item,key) => {
                ar = item > aver ? aver : item;
        });
        return ar;
};

/*函数 :从原始lrc歌词获取信息并存入 n*3 数组*/
let getLrcAr = (text) => {
        let lrcAr = [];
        let calcRule = ;
        for(x of text.split('\n')) {
                let ar = [];
                let re = /\d+[\.:]\d+([\.:]\d+)?/g;
                let geci = x.replace(re,'');
                if(geci) {
                        geci = geci.replace(/[\[\]\'\"\t,]s?/g,'');
                        let time = x.match(re);
                        if(time != null) {
                                for(y of time) {
                                        let tmp = y.match(/\d+/g);
                                        let sec = 0;
                                        for(z in tmp) sec += tmp * calcRule;
                                        ar = ;
                                        lrcAr.push(ar);
                                }
                        }
                }
        }
        lrcAr.sort((a,b)=> a - b);
        return(lrcTime(lrcAr));
};

/*函数 :模拟显示同步歌词*/
let showLrc = (time) => {
        let name = mFlag ? 'cover1' : 'cover2';
        lrc.innerHTML = lrcAr;
        lrc.dataset.lrc = lrcAr;
        lrc.style.setProperty('--motion', name);
        lrc.style.setProperty('--tt', time + 's');
        lrc.style.setProperty('--state', 'running');
        mKey += 1;
        mFlag = !mFlag;
};

/*函数 :处理当前歌词索引 mKey*/
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 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 mState = () => aud.paused ? (lrc.style.setProperty('--state','paused'),mplayer.style.animationPlayState = 'paused') : (lrc.style.setProperty('--state','running'),mplayer.style.animationPlayState = 'running');

/*监听播放进度*/
aud.addEventListener('timeupdate', () => {
        for (j = 0; j < lrcAr.length; j++) {
                if (aud.currentTime >= lrcAr) {
                        cKey = j;
                        if (mKey === j) showLrc(lrcAr);
                        else continue;
                }
        }
});
aud.addEventListener('pause', () => mState());/*监听暂停事件*/
aud.addEventListener('play', () => mState());/*监听播放事件*/
aud.addEventListener('seeked', () => calcKey());/*监听查询事件*/
let lrcAr = getLrcAr(lrcStr); /*获得歌词数组*/
})();


let fs = true;
        fullscreen.onclick = () => {
                fs ? (fullscreen.innerText = '退出全屏',papa.requestFullscreen()) : (fullscreen.innerText = '全屏观赏', document.exitFullscreen());
                fs = !fs;
        };
</script>

红影 发表于 2023-5-14 22:32

又还是一个都是动画的轮转的帖子,真漂亮。欣赏亚伦老师好帖{:4_187:}

醉美水芙蓉 发表于 2023-5-14 22:50

焱鑫磊 发表于 2023-5-14 23:21

欣赏老师佳作!{:4_187:}{:4_187:}{:4_187:}
页: [1]
查看完整版本: 找一个笑着流泪的借口