亚伦影音工作室 发表于 2023-5-21 14:49

动图,动画全控《敬以后(DJ 默涵版)》

本帖最后由 亚伦影音工作室 于 2023-5-21 14:49 编辑 <br /><br /><style>

#papa {

        margin: 100px -300px;

        width: 1164px;

        height: 620px;

        background: linear-gradient(41deg, rgba(251, 7, 7, 0.33) 0%,rgba(6, 19, 157, 0.31) 44%,rgba(19, 233, 63, 0.56) 100%),url('http://')0 0/100% 100%;

        position: relative;

        z-index: 1;overflow: hidden;}

#dt{position: absolute;top:0%; left:0%;z-index: 1;

        width:100%;         

        height:100%;transform: rotateY(0deg);opacity: 1}

.photo {width: 100%;

height: 100%;

position: absolute;z-index: 2;

border:3px solid #ffffff;

top:0px; left:0px;filter:contrast(120%)brightness(100%);

opacity: 0;

animation: round 90s linear infinite;}



@keyframes round{0% {opacity: 1;transform:translate(-100%,-100%)scale(0);}

4% {opacity: 1;transform:translate(0%,0%)scale(0.6)rotate(-360deg);}

5% {opacity: 1;transform:translate(0%,0%)scale(0.7)rotate(-360deg);}

7% {opacity: 1;transform: perspective(1300px) rotateY(70deg)scale(0.7)}

9% {opacity: 1;transform: perspective(1300px) rotateY(-70deg)scale(0.7)}

11% {opacity: 0;transform:translate(100%,100%) perspective(1300px)rotatex(-90deg) rotateY(-40deg)scale(3);}

}



img:nth-child(1) {animation-delay: 84s;}

img:nth-child(2) {animation-delay: 78s;}

img:nth-child(3) {animation-delay: 72s;}

img:nth-child(4) {animation-delay: 66s;}

img:nth-child(5) {animation-delay: 60s;}

img:nth-child(6) {animation-delay: 54s;}

img:nth-child(7) {animation-delay: 48s;}

img:nth-child(8) {animation-delay: 42s;}

img:nth-child(9) {animation-delay: 36s;}

img:nth-child(10){animation-delay: 30s;}

img:nth-child(11){animation-delay: 24s;}

img:nth-child(12){animation-delay: 18s;}

img:nth-child(13){animation-delay: 12s;}

img:nth-child(14) {animation-delay: 6s;}

img:nth-child(15) {animation-delay: 0s;}

.stop img:nth-child(1),

.stop img:nth-child(2),

.stop img:nth-child(3),

.stop img:nth-child(4),

.stop img:nth-child(5),

.stop img:nth-child(6),

.stop img:nth-child(7),

.stop img:nth-child(8),

.stop img:nth-child(9),

.stop img:nth-child(10),

.stop img:nth-child(11),

.stop img:nth-child(12),

.stop img:nth-child(13),

.stop img:nth-child(14),

.stop img:nth-child(15){animation-play-state: paused;}





#vid { display: none; }

#canv {   mix-blend-mode:soft-light;

        position: absolute;

        display: block;z-index: 2;

        top:-5%; left:0%;

transform:scale(1,1.1);

        opacity: 0;

}

</style>





<div id="papa">



<div id='dt'><img id="testImg0" src="https://www.yiyuen.com/e/file/view/586581" width="100%" height="100%"></div>

<div id="testImg" >

<img alt="" class="photo" src="https://file.moyublog.com/d/file/2021-11-17/nyv0qsjh0s2.jpg" />

<img alt="" class="photo"src="https://file.moyublog.com/d/file/2022-12-02/365f5998753741a910fac58b2be63d91.jpg" />

<img alt=""class="photo"src="https://365.tf/disk/tf/1676473345.jpg" />

<img alt="" class="photo" src="https://365.tf/disk/tf/1676383211.jpg" />

<img alt="" class="photo" src="https://365.tf/disk/tf/1676420707.jpg" />

<img alt="" class="photo" src="https://365.tf/disk/tf/1676438603.jpg" />

<img alt="" class="photo" src="https://365.tf/disk/tf/1676393369.jpg" />

<img alt="" class="photo" src="https://file.moyublog.com/d/file/2022-09-20/66695b8106d2596e6b1cd5c6cb77eda6.jpg" />

<img alt="" class="photo" src="https://365.tf/disk/tf/1676392055.jpg" />

<img alt="" class="photo"src="https://365.tf/disk/tf/1676436325.jpg" />

<img alt=""class="photo"src="https://365.tf/disk/tf/1676409961.jpg" />

<img alt="" class="photo" src="https://file.moyublog.com/d/file/2021-01-18/c02923924e30e172098ec67a6ae5fc94.jpg" />

<img alt="" class="photo" src="https://365.tf/disk/tf/1676421148.jpg" />

<img alt="" class="photo" src="https://365.tf/disk/tf/1676449988.jpg" />

<img alt="" class="photo" src="https://file.moyublog.com/d/file/2022-05-31/8db359878f7ab03dd2e8e4b0badf2be7.jpg" />

</div>

<canvas id="canv"></canvas>

<div data-lrc="亚伦影音工作室" id="lrc" title="暂停/播放">亚伦影音工作室</div>

</div>

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

<video id="vid" src="https://img.tukuppt.com/video_show/2269348/00/17/44/5ec497a38f522.mp" loop autoplay muted></video>





<style type="text/css">

#lrc {

        --state: paused;

        --motion: cover2;

        --tt: 2s;

        --bg: linear-gradient(180deg, #880000, #880000);

        position: absolute;z-index: 4;

        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 = `敬以后(DJ 默涵版)

演唱:魏佳艺

词:聂小慧

曲:聂小慧

编曲:王亚东

吉他:杨春

和声:小佑

混音:王亚东

制作人:聂小慧

光阴似水匆匆它不停留

一晃白了谁的少年头

多少动人故事频频再回首

只能徒增满心的忧愁

向那旧尘往事作别挥挥手

曾经沧海都各自游走

多少的是非恩怨爱恨情仇

就让它随那时间漂流

举起这一杯中酒 敬我们的以后

一切都看透 来个一醉方休

举起这一杯中酒敬我们的以后

咽下喜怒哀乐 还要继续走

光阴似水匆匆它不停留

一晃白了谁的少年头

多少动人故事频频再回首

只能徒增满心的忧愁

向那旧尘往事作别挥挥手

曾经沧海都各自游走

多少的是非恩怨爱恨情仇

就让它随那时间漂流

举起这一杯中酒 敬我们的以后

一切都看透 来个一醉方休

举起这一杯中酒敬我们的以后

咽下喜怒哀乐 还要继续走

举起这一杯中酒 敬我们的以后

一切都看透 来个一醉方休

举起这一杯中酒敬我们的以后

咽下喜怒哀乐 还要继续走

`;



/*变量 :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;

}







/*监听播放进度*/

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); /*获得歌词数组*/

lrc.addEventListener('click', () => aud.paused ? aud.play() : aud.pause());

})();

</script>



<script>

let ctx = canv.getContext('2d');

let ww = canv.width =1164, hh = canv.height =620;

let loop = () => {ctx.drawImage(vid, 0, 0, ww, hh);if(!vid.paused) {requestAnimationFrame(loop);return;}}



let mState = () => aud.paused ? (papa.style.setProperty('--state', 'paused'),vid.pause()) : (papa.style.setProperty('--state', 'running'),vid.play());

vid.playbackRate = 0.5;

vid.addEventListener('play', loop, false);

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

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



</script>



<script>

if ('getContext' in document.createElement('canvas')) {

    HTMLImageElement.prototype.play = function() {

      if (this.storeCanvas) {

            // 移除存储的canvas

            this.storeCanvas.parentElement.removeChild(this.storeCanvas);

            this.storeCanvas = null;

            // 透明度还原

            image0.style.opacity = '';

      }

      if (this.storeUrl) {

            this.src = this.storeUrl;   

      }

    };

    HTMLImageElement.prototype.stop = function() {

      var canvas = document.createElement('canvas');

      // 尺寸

      var width = this.width, height = this.height;

      if (width && height) {

            // 存储之前的地址

            if (!this.storeUrl) {

                this.storeUrl = this.src;

            }

            // canvas大小

            canvas.width = width;

            canvas.height = height;

            // 绘制图片帧(第一帧)

            canvas.getContext('2d').drawImage(this, 0, 0, width, height);

            // 重置当前图片

            try {

                this.src = canvas.toDataURL("image/gif");

            } catch(e) {

                // 跨域

                this.removeAttribute('src');

                // 载入canvas元素

                canvas.style.position = 'absolute';

                // 前面插入图片

                this.parentElement.insertBefore(canvas, this);

                // 隐藏原图

                this.style.opacity = '0';

                // 存储canvas

                this.storeCanvas = canvas;

            }

      }

    };

}



var image0 = document.getElementById("testImg0"),

image = document.getElementById("testImg"),

    button = document.getElementById("lrc");

    if (image0&&image && button) {

    button.onclick = function() {

      if (this.value == '') {

         image0.play(); image.classList.remove('stop');

            this.value = '.';

      } else {

            image0.stop();image.classList.add('stop');

            this.value = '';

      }

    };

}



</script>

红影 发表于 2023-5-21 16:50

轮播的图片很漂亮。背景的动图也很漂亮。欣赏亚伦老师好帖{:4_187:}

红影 发表于 2023-5-21 16:52

暂停后的确都可以停下来。后面的动图好像是替换成了静图呢。

梦缘 发表于 2023-5-21 20:00

好美的帖,老师好棒啊!{:4_204:}

焱鑫磊 发表于 2023-5-21 20:56

棒棒哒!赞!{:4_187:}
页: [1]
查看完整版本: 动图,动画全控《敬以后(DJ 默涵版)》