福宝 发表于 2024-6-30 22:19

画里拾光

本帖最后由 福宝 于 2024-6-30 22:21 编辑 <br /><br /><style>
    #papa { --width: 1650px; margin: 120px 0 20px calc(50% - (var(--width) / 2 + 90px)); width: var(--width); height: 1000px; background: url('https://gd-hbimg.huaban.com/a9c6f427780ddd5a727ec6bf4121c2ab1e10aad9fae4b-cibV3q') no-repeat center/cover; box-shadow: 3px 3px 8px #666; user-select: none; z-index: 1; position: relative; }
    #papa::before { position: absolute;right:39%; content: url('https://gd-hbimg.huaban.com/49e442019ae97d92226ab873054a0648f783f1867d1d-UQFEO7_fw1200'); mix-blend-mode: lighten; filter: blur(1px); }
    #txtbox { position: absolute; left: 810px; top:270px; width: 300px; min-height: 60px; padding: 10px 20px; box-sizing: border-box; overflow: hidden;writing-mode:vertical-lr; opacity:.55;}
    #txtbox p { position: relative; margin: 4px 0; padding: 0; font: normal 16px/23px sans-serif; color:Snow; txtAr-shadow: 1px 1px 1px gray; animation: 2s forwards;}
    #player { position: absolute; width: 180px; LEFT: 450px; bottom: 100px; cursor: pointer; animation: rot 6s linear infinite; }
    #vid { position: absolute; width: 100%; height: 80%; object-fit: cover; mix-blend-mode: screen; opacity: 0.5; pointer-events: none; }
    .tMid, .tRight { display: inline-block; width: 100%; }
    .tMid { text-align: center; }
    .tRight { text-align:right; font-size: 15px;}
    @keyframes move { to { transform: translate(0); } }
    @keyframes rot { to { transform: rotate(360deg); } }
</style>

<div id="papa">
    <audio id="aud" src="https://music.163.com/song/media/outer/url?id=1451572449" autoplay loop></audio>
    <video id="vid" src="https://img.tukuppt.com/video_show/15653652/00/79/86/60c98c8146068.mp4" muted autoplay loop></video>
    <div id="txtbox"></div>
    <img id="player" alt="" src="https://gd-hbimg.huaban.com/cb667ffd4610a5e19f05a4fa9c213dac5113a64319cb2-pf5X2z_fw1200" title"播放/暂停" />
</div>



<script>
var txtAr = [
    `<span class="tMid">
   访戴天山道士不遇</span>
    <br>
    \n犬吠水声中,桃花带露浓。 \n树深时见鹿,溪午不闻钟。 \n野竹分青霭,飞泉挂碧峰。 \n无人知所去,愁倚两三松。\n
<span class="tRight">----李白</span>`,
];
var curIdx = 0;
var paras = [];
var ww = txtbox.offsetWidth;

var addPs = () => {
    var txtstr = txtAr;
    txtbox.innerHTML = '';
    paras.length = 0;
    var ar = txtstr.split(/\n/).filter(item => item !=='');
    ar.forEach((p,k) => {
      var para = document.createElement('p');
      para.innerHTML = p;
      para.style.cssText += `transform: translate(${ww}px);`;
      txtbox.appendChild(para);
      paras.push(para);
    });
    curIdx = (curIdx + 1) % txtAr.length;
    mkAni();
};

var parasReset = () => {
    addPs();
    paras.forEach(p => {
      p.style.animationName = '';
      p.style.transform = 'translate(${ww}px)';
      setTimeout( () => { paras.style.animationName = 'move'; }, 500);
    });
};

var mkAni = () => {
    paras.forEach((p,k) => {
      p.onanimationend = () => {
            paras[(k+1) % paras.length].style.animationName = 'move';
            if(k === paras.length - 1) setTimeout( () => parasReset(), 10000);
      };
    });
};

var mState = () => {
    [...paras,...].forEach(p => p.style.animationPlayState = aud.paused ? 'paused' : 'running');
    aud.paused ?vid.pause() : vid.play();
    player.title = ['暂停', '播放'][+aud.paused];
};

aud.oncanplay = aud.onplaying = aud.onpause = () => mState();
player.onclick = () => aud.paused ? aud.play() : aud.pause();

addPs();
paras.style.animationName = 'move';

</script>

蜻蜓 发表于 2024-7-1 21:10

这图很好{:10_402:}
页: [1]
查看完整版本: 画里拾光