焱鑫磊 发表于 2023-8-21 11:52

《爱上你是一个错》半吨兄弟

本帖最后由 焱鑫磊 于 2023-8-25 11:23 编辑 <br /><br /><style >
#papa{margin: 100px -300px ;width: 1200px;box-shadow: 0px 0px 0px 2px #cccccc, 0px 0px 0px 6px #880000; overflow: hidden;
height: 680px;border: 1px solid;background: #333 ; position: relative;z-index: 12345;}
.photo {width: 100%;
height: 100%;
position: absolute;z-index: 2;
top:0px; left:0px;
opacity: 0;
animation: round 270s linear infinite;}
@keyframes round{
0% {
-webkit-transform:rotate(0)scale(1)translate(0%,0%);
opacity:0}
2% {
-webkit-transform:rotate(0)scale(1.5)translate(-10%,0%);
opacity:1}
4% {
-webkit-transform:rotate(0)scale(1.5)translate(0%,10%)rotateZ(0deg);
opacity:1}
6% {
-webkit-transform:rotate(0)scale(1.5)translate(0%,-10%)rotateZ(0deg);
opacity:1}
8% {
-webkit-transform:rotate(0)scale(1.5)translate(10%,0%)rotateZ(0deg);
opacity:1}
10% {
-webkit-transform:rotate(0deg)scale(1.5)translate(0%,0%)rotateZ(0deg);
opacity:0}
}
img:nth-child(1) {animation-delay: 252s;}
img:nth-child(2) {animation-delay: 234s;}
img:nth-child(3) {animation-delay: 216s;}
img:nth-child(4) {animation-delay: 198s;}
img:nth-child(5) {animation-delay: 180s;}
img:nth-child(6) {animation-delay: 162s;}
img:nth-child(7) {animation-delay: 144s;}
img:nth-child(8) {animation-delay: 126s;}
img:nth-child(9) {animation-delay: 108s;}
img:nth-child(10){animation-delay: 90s;}
img:nth-child(11){animation-delay: 72s;}
img:nth-child(12){animation-delay: 54s;}
img:nth-child(13){animation-delay: 36s;}
img:nth-child(14) {animation-delay: 18s;}
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;}
#dt{position: absolute;top:0%; left:0%;width: 100%;height: 100%;mix-blend-mode: lighten;z-index: 3; transform: rotateX(180deg);}
#mplayer {
      position: absolute;z-index: 890;
      width: 30px;
      height: 30px;
top:93%; left:50%;
      border: 2px solid #FFFFFF;
      border-radius: 50%;
      box-shadow: 0 0 10px #00FF00;
      transition: .7s;
      cursor: pointer;
      display: grid;
      place-items: center;
      --play: 1; --pause: 0; --bd: black; --sd: black;
}
#mplayer::before, #mplayer::after {
      position: absolute;
      content: '';
      border-style: solid;
      border-color: #FFFFFF;
      transition: .2;
}
#mplayer::before {
      width: 0;
      height: 0;
      left: 10px;
      border-width: 10px 12px;
      border-color: transparent transparent transparent #FFFFFF;
   opacity: var(--play);
}
#mplayer::after {
      width: 2px;
      height: 16px;
      border-width: 0 4px 0 4px;
      opacity: var(--pause);
}
#mplayer:hover { box-shadow: 0 0 6px #000000, 0 0 6px #000000 inset; }
#tit {position: absolute;
      width: fit-content;
      height: fit-content;
      left:5%;top:30px;
      z-index: 12;
      color: #ff0000;
filter:drop-shadow(#FFFFFF 1px 0 0)drop-shadow(#FFFFFF 0 1px 0)drop-shadow(#FFFFFF -1px 0 0) drop-shadow(#FFFFFF 0 -1px0);
       font: normal 25px/32px '华文隶书',serif;
}
.mysp {position: relative;
      display: block;
}

@keyframes move {
      0% { left: 10px;top:0px; transform: rotate(0); color: #000080; }
      50% {left:150px;top:0px; transform: rotate(360deg); color: red; }
      100% {left:10px;top:0px; transform: rotate(720deg); color: green; }
}
#papa:hover #fullscreen { display:block ;}
#fullscreen { position: absolute; top:5%; left:83%;color:#ffffff; filter:drop-shadow( 1px 1px 1px #000000);font: normal 2.2em华文隶书; opacity: 1; cursor: pointer; z-index: 1111}
</style>
<div id="papa">
<span id="fullscreen">全屏观赏</span>
<div id="tit"></div>
<div id='dt'><img id="Img" src="https://pic.imgdb.cn/item/6412e67aebf10e5d530a990b.gif" width="100%" height="100%"></div>
<div id="testImg" >
<img alt="" class="photo" src="https://pic.imgdb.cn/item/64e18366661c6c8e54ca3c69.jpg" />
<img alt="" class="photo" src="https://pic.imgdb.cn/item/64e1839b661c6c8e54cb13dd.jpg" />
<img alt="" class="photo" src="https://pic.imgdb.cn/item/64e183b2661c6c8e54cb6498.jpg" />
<img alt="" class="photo" src="https://pic.imgdb.cn/item/64e183c9661c6c8e54cbbf14.jpg" />
<img alt=""class="photo"src="https://pic.imgdb.cn/item/64e183eb661c6c8e54cc42e8.jpg" />
<img alt="" class="photo" src="https://pic.imgdb.cn/item/64e18407661c6c8e54cca2c7.jpg" />
<img alt="" class="photo" src="https://pic.imgdb.cn/item/64e1841e661c6c8e54ccf499.jpg" />
<img alt="" class="photo" src="https://pic.imgdb.cn/item/64e18437661c6c8e54cd9e50.jpg" />
<img alt="" class="photo" src="https://pic.imgdb.cn/item/64e18454661c6c8e54ce0562.jpg" />
<img alt="" class="photo" src="https://pic.imgdb.cn/item/64e18471661c6c8e54ce6544.jpg" />
<img alt=""class="photo"src="https://pic.imgdb.cn/item/64e1848a661c6c8e54ceb4a0.jpg" />
<img alt="" class="photo" src="https://pic.imgdb.cn/item/64e184a1661c6c8e54cf000a.jpg" />
<img alt="" class="photo" src="https://pic.imgdb.cn/item/64e184bb661c6c8e54cf5477.jpg" />
<img alt="" class="photo" src="https://pic.imgdb.cn/item/64e184ee661c6c8e54cffb62.jpg" />
<img alt="" class="photo" src="https://pic.imgdb.cn/item/64e184d2661c6c8e54cf9f9d.jpg" />

</div>

<p id="mplayer" ></p>
<div id="lrc" data-lrc="学习制作">学习制作</div>
</div>
<audio id="MusicPlayer" src="https://i.mp3.wf/view.php/8717cf83e664a52d59e8d2a36c312562.mp3" loop autoplay></audio>
<style>
#lrc {
        --state: paused;
        --motion: cover2;
        --tt: 2s;
        --bg: linear-gradient(180deg, #880000, #880000);
        position: absolute;
        left: 50%;z-index: 2;
        transform: translate(-50%);
        top: 82%;
        font:normal 3em 华文隶书;
        color: #000080;
        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;filter:hue-rotate(0deg)brightness(350%); } to { width: 100%;filter:hue-rotate(360deg)brightness(200%)} }
@keyframes cover2 { from { width: 0;filter:hue-rotate(0deg)brightness(350%); } to { width: 100%;filter:hue-rotate(360deg)brightness(200%)} }

</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 (MusicPlayer.currentTime <= lrcAr) {
                        mKey = j - 1;
                        break;
                }
        }
        if (mKey < 0) mKey = 0;
        if (mKey > lrcAr.length - 1) mKey = lrcAr.length - 1;
        let time = lrcAr - (MusicPlayer.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 = () => MusicPlayer.paused ? (lrc.style.setProperty('--state','paused'),mplayer.style.animationPlayState = 'paused') : (lrc.style.setProperty('--state','running'),mplayer.style.animationPlayState = 'running');

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

})();
mplayer.style.animationPlayState = MusicPlayer.paused ? 'paused' : 'running';
MusicPlayer.addEventListener('playing', () =>mplayer.style.animationPlayState = 'running');
MusicPlayer.addEventListener('pause', () =>mplayer.style.animationPlayState = 'paused');

let spans = [],idx = 0, last = null;

      [...'爱上你是一个错'].forEach((item,key) => {
                let sp = document.createElement('span');
                sp.className = 'mysp';
                sp.innerHTML = item + '<br>';
                spans.push(sp);
                tit.appendChild(sp);
      });

      let mov = () => {
                if(last != null) spans.style.animation = '';
                spans.style.animation = 'move 2s';
                last = idx;
                idx += 1;
                if(idx >= spans.length) idx = 0;
                setTimeout(mov,2000);
      };

      mov();
let fs = true;
        fullscreen.onclick = () => {
                fs ? (fullscreen.innerText = '退出全屏', papa.requestFullscreen()) : (fullscreen.innerText = '全屏观赏', document.exitFullscreen());
                fs = !fs;
        };
</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;
            // 透明度还原
            image.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 image= document.getElementById("Img");
var imagee= document.getElementById("testImg");
let mState = () => MusicPlayer.paused ? (mplayer.style.setProperty('--play', '1'),image.stop(),imagee.classList.add('stop') ,mplayer.style.setProperty('--pause', '0')) : (mplayer.style.setProperty('--play', '0'), image.play(),imagee.classList.remove('stop'),mplayer.style.setProperty('--pause', '1'));
mplayer.onclick = () => MusicPlayer.paused ? MusicPlayer.play() : MusicPlayer.pause();
MusicPlayer.addEventListener('play', mState,false);
MusicPlayer.addEventListener('pause', mState,false);
</script>

红影 发表于 2023-8-21 13:16

好漂亮的特效音画,背景很美,制作也很完美,给焱鑫磊点赞{:4_199:}

焱鑫磊 发表于 2023-8-21 14:09

红影 发表于 2023-8-21 13:16
好漂亮的特效音画,背景很美,制作也很完美,给焱鑫磊点赞

学习制作!代码:亚伦。{:4_187:}

红影 发表于 2023-8-21 16:29

焱鑫磊 发表于 2023-8-21 14:09
学习制作!代码:亚伦。

知道的,正好前面看到过亚伦老师类似的帖子{:4_173:}

小辣椒 发表于 2023-8-21 19:45

速度的,今天上来一下子看见三个帖了{:4_199:}

小辣椒 发表于 2023-8-21 19:48

亚伦的代码加效果比较灵活,变化也是流畅{:4_199:}

小辣椒 发表于 2023-8-21 19:50

谢谢分享,我手机上来,你那三个字的名字我打字打不出{:4_189:}

焱鑫磊 发表于 2023-8-21 21:43

小辣椒 发表于 2023-8-21 19:45
速度的,今天上来一下子看见三个帖了

有时间就多玩儿一会儿。{:4_172:}

焱鑫磊 发表于 2023-8-21 21:44

小辣椒 发表于 2023-8-21 19:48
亚伦的代码加效果比较灵活,变化也是流畅

问好小辣椒!{:4_187:}

焱鑫磊 发表于 2023-8-21 21:44

小辣椒 发表于 2023-8-21 19:50
谢谢分享,我手机上来,你那三个字的名字我打字打不出

{:4_208:}
页: [1]
查看完整版本: 《爱上你是一个错》半吨兄弟