马黑黑 发表于 2024-3-7 13:01

Lost in Time

本帖最后由 马黑黑 于 2024-3-7 13:46 编辑 <br /><br /><style>
#papa { margin: 0 0 0 calc(50% - 593px); width: 1024px; height: 640px; background:url('https://638183.freep.cn/638183/t24/1/lost.jpg') no-repeat center/cover; box-shadow: 3px 3px 20px #000; transition: filter 1s; position: relative; z-index: 1; }
#papa:hover { filter: brightness(1.2); }
#player { position: absolute; left: 620px; top: 540px; width: 100px; border-radius: 50%; transition: 4s; cursor: pointer; animation: rot .5s infinite alternate var(--state); }
#vid { position: absolute; width: 100%; height: 100%; object-fit: cover; mix-blend-mode: screen; pointer-events: none; clip-path: polygon(0 0,80% 0,80% 20%,100% 20%,100% 100%,0 100%); }
@keyframes rot { to { transform: scale(.8); } }
</style>

<div id="papa">
        <img id="player" src="https://638183.freep.cn/638183/t22/51/tree_133167802617361953.jpg" alt="" />
        <video id="vid" src="https://img.tukuppt.com/video_show/15653652/01/23/79/62204e70cf64d.mp4" loop muted></video>
        <audio id="aud" src="https://music.163.com/song/media/outer/url?id=17961738" autoplay loop></audio>
</div>

<script>
(function() {
        let sF = document.createElement('script');
        sF.src = 'https://638183.freep.cn/638183/web/api/fullscreen.js';
        sF.charset = 'utf-8';
        document.querySelector('body').appendChild(sF);
        sF.onload = () => FS({papa: '#papa'});
        let getOffsetPos = (ele) => {
                let x = ele.offsetLeft, y = ele.offsetTop, pa = ele.offsetParent;
                while(pa != null) {
                        x += pa.offsetLeft;
                        y += pa.offsetTop;
                        pa = pa.offsetParent;
                }
                return {x, y};
        };
        let mState = () => aud.paused
                ? (papa.style.setProperty('--state','paused'), vid.pause())
                : (papa.style.setProperty('--state','running'), vid.play());
        aud.onpause = () => mState();
        aud.onplaying = () => mState();
        player.onclick = () => aud.paused ? aud.play() : aud.pause();
        let movTimer = null,
                paWidth = papa.clientWidth,
                paHeight = papa.clientHeight,
                sonSize = player.clientWidth,
                bodyWidth = document.body.clientWidth,
                bodyHeight = document.body.clientHeight,
                paOffset = {x: getOffsetPos(papa).x, y: getOffsetPos(papa).y};
        document.onmousemove = function(e) {
                clearTimeout(movTimer);
                movTimer = setTimeout(function() {
                        if(e.target.id === "player") return;
                        if(document.fullscreenElement === null) {
                                let x = e.pageX, y = e.pageY;
                                if(x < paOffset.x) x = paOffset.x;
                                if(y < paOffset.y) y = paOffset.y;
                                x = x - paOffset.x;
                                y = y - paOffset.y;
                                if(x + sonSize >= paWidth) x = paWidth - sonSize;
                                if(y + sonSize >= paHeight) y = paHeight - sonSize;
                                player.style.cssText += `left: ${x}px; top: ${y}px`;
                        } else {
                                let xx = e.offsetX || e.layerX, yy = e.offsetY || e.layerY;
                                if(xx + sonSize > bodyWidth) xx -= sonSize;
                                if(yy + sonSize > bodyHeight) yy -= sonSize;
                                player.style.cssText += `left: ${xx}px; top: ${yy}px`;
                        }
                }, 400);
        };
})();
</script>

马黑黑 发表于 2024-3-7 13:01

本帖最后由 马黑黑 于 2024-3-7 13:47 编辑 <br /><br /><style>
.mum { position: relative; margin: 0; padding: 10px; font: normal 16px/20px Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; color: black; background: rgba(240, 240, 240,.95); box-shadow: 2px 2px 4px gray; border: thick groove lightblue; border-radius: 6px; }
.mum ::selection { background-color: rgba(0,100,100,.35); }
.mum div { margin: 0; padding: 0; }
.mum cl-cd { display: block; position: relative; margin: 0 0 0 50px; padding: 0 0 0 10px; white-space: pre-wrap; overflow-wrap: break-word; border-left: 1px solid silver; }
.mum cl-cd::before { position: absolute; content: attr(data-idx); width: 50px; color: gray; text-align: right; transform: translate(-70px); }
.tRed { color: red; }
.tBlue { color: blue; }
.tGreen { color: green; }
.tDarkRed { color: darkred; }
.tMagenta { color: magenta; }
</style>
<h2>帖子代码</h2>
<div class='mum'>
<cl-cd data-idx="1">&lt;<span class="tDarkRed">style</span>&gt;</cl-cd>
<cl-cd data-idx="2">&nbsp; &nbsp; #papa { <span class="tBlue">margin:</span> 0 0 0 calc(50% - 593px); <span class="tBlue">width:</span> 1024px; <span class="tBlue">height:</span> 640px; <span class="tBlue">background:</span>url(<span class="tMagenta">'https://638183.freep.cn/638183/t24/1/lost.jpg'</span>) no-repeat center/cover; <span class="tBlue">box-shadow:</span> 3px 3px 20px #000; <span class="tBlue">transition:</span> filter 1s; <span class="tBlue">position:</span> relative; <span class="tBlue">z-index:</span> 1; }</cl-cd>
<cl-cd data-idx="3">&nbsp; &nbsp; #<span class="tBlue">papa:</span>hover { <span class="tBlue">filter:</span> brightness(1.2); }</cl-cd>
<cl-cd data-idx="4">&nbsp; &nbsp; #player { <span class="tBlue">position:</span> absolute; <span class="tBlue">left:</span> 620px; <span class="tBlue">top:</span> 540px; <span class="tBlue">width:</span> 100px; <span class="tBlue">border-radius:</span> 50%; <span class="tBlue">transition:</span> 4s; <span class="tBlue">cursor:</span> pointer; <span class="tBlue">animation:</span> rot .5s infinite alternate <span class="tBlue">var</span>(--state); }</cl-cd>
<cl-cd data-idx="5">&nbsp; &nbsp; #vid { <span class="tBlue">position:</span> absolute; <span class="tBlue">width:</span> 100%; <span class="tBlue">height:</span> 100%; <span class="tBlue">object-fit:</span> cover; <span class="tBlue">mix-blend-mode:</span> screen; <span class="tBlue">pointer-events:</span> none; <span class="tBlue">clip-path:</span> polygon(0 0,80% 0,80% 20%,100% 20%,100% 100%,0 100%); }</cl-cd>
<cl-cd data-idx="6">&nbsp; &nbsp; @keyframes rot { to { <span class="tBlue">transform:</span> scale(.8); } }</cl-cd>
<cl-cd data-idx="7">&lt;<span class="tDarkRed">/style</span>&gt;</cl-cd>
<cl-cd data-idx="8">&nbsp;</cl-cd>
<cl-cd data-idx="9">&lt;<span class="tDarkRed">div</span> <span class="tRed">id</span>=<span class="tMagenta">"papa"</span>&gt;</cl-cd>
<cl-cd data-idx="10">&nbsp; &nbsp; &lt;<span class="tDarkRed">img</span> <span class="tRed">id</span>=<span class="tMagenta">"player"</span> src=<span class="tMagenta">"https://638183.freep.cn/638183/t22/51/tree_133167802617361953.jpg"</span> alt=<span class="tMagenta">""</span> /&gt;</cl-cd>
<cl-cd data-idx="11">&nbsp; &nbsp; &lt;<span class="tDarkRed">video</span> <span class="tRed">id</span>=<span class="tMagenta">"vid"</span> src=<span class="tMagenta">"https://img.tukuppt.com/video_show/15653652/01/23/79/62204e70cf64d.mp4"</span> loop muted&gt;&lt;<span class="tDarkRed">/video</span>&gt;</cl-cd>
<cl-cd data-idx="12">&nbsp; &nbsp; &lt;<span class="tDarkRed">audio</span> <span class="tRed">id</span>=<span class="tMagenta">"aud"</span> src=<span class="tMagenta">"https://music.163.com/song/media/outer/url?<span class="tRed">id</span>=17961738"</span> autoplay loop&gt;&lt;<span class="tDarkRed">/audio</span>&gt;</cl-cd>
<cl-cd data-idx="13">&lt;<span class="tDarkRed">/div</span>&gt;</cl-cd>
<cl-cd data-idx="14">&nbsp;</cl-cd>
<cl-cd data-idx="15">&lt;<span class="tDarkRed">script</span>&gt;</cl-cd>
<cl-cd data-idx="16">(<span class="tBlue">function</span>() {</cl-cd>
<cl-cd data-idx="17">&nbsp; &nbsp; <span class="tBlue">let</span> sF = <span class="tRed">document</span>.createElement(<span class="tMagenta">'script'</span>);</cl-cd>
<cl-cd data-idx="18">&nbsp; &nbsp; sF.src = <span class="tMagenta">'https://638183.freep.cn/638183/web/api/fullscreen.js'</span>;</cl-cd>
<cl-cd data-idx="19">&nbsp; &nbsp; sF.charset = <span class="tMagenta">'utf-8'</span>;</cl-cd>
<cl-cd data-idx="20">&nbsp; &nbsp; <span class="tRed">document</span>.querySelector(<span class="tMagenta">'body'</span>).appendChild(sF);</cl-cd>
<cl-cd data-idx="21">&nbsp; &nbsp; sF.onload = () =&gt; FS({<span class="tBlue">papa:</span> <span class="tMagenta">'#papa'</span>});</cl-cd>
<cl-cd data-idx="22">&nbsp; &nbsp; <span class="tBlue">let</span> getOffsetPos = (ele) =&gt; {</cl-cd>
<cl-cd data-idx="23">&nbsp; &nbsp; &nbsp; &nbsp; <span class="tBlue">let</span> x = ele.offsetLeft, y = ele.offsetTop, pa = ele.offsetParent;</cl-cd>
<cl-cd data-idx="24">&nbsp; &nbsp; &nbsp; &nbsp; <span class="tBlue">while</span>(pa != null) {</cl-cd>
<cl-cd data-idx="25">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x += pa.offsetLeft;</cl-cd>
<cl-cd data-idx="26">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y += pa.offsetTop;</cl-cd>
<cl-cd data-idx="27">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pa = pa.offsetParent;</cl-cd>
<cl-cd data-idx="28">&nbsp; &nbsp; &nbsp; &nbsp; }</cl-cd>
<cl-cd data-idx="29">&nbsp; &nbsp; &nbsp; &nbsp; <span class="tBlue">return</span> {x, y};</cl-cd>
<cl-cd data-idx="30">&nbsp; &nbsp; };</cl-cd>
<cl-cd data-idx="31">&nbsp; &nbsp; <span class="tBlue">let</span> mState = () =&gt; aud.paused</cl-cd>
<cl-cd data-idx="32">&nbsp; &nbsp; &nbsp; &nbsp; ? (papa.style.setProperty(<span class="tMagenta">'--state'</span>,<span class="tMagenta">'paused'</span>), vid.pause())</cl-cd>
<cl-cd data-idx="33">&nbsp; &nbsp; &nbsp; &nbsp; : (papa.style.setProperty(<span class="tMagenta">'--state'</span>,<span class="tMagenta">'running'</span>), vid.play());</cl-cd>
<cl-cd data-idx="34">&nbsp; &nbsp; aud.onpause = () =&gt; mState();</cl-cd>
<cl-cd data-idx="35">&nbsp; &nbsp; aud.onplaying = () =&gt; mState();</cl-cd>
<cl-cd data-idx="36">&nbsp; &nbsp; player.onclick = () =&gt; aud.paused ? aud.play() : aud.pause();</cl-cd>
<cl-cd data-idx="37">&nbsp; &nbsp; <span class="tBlue">let</span> movTimer = null,</cl-cd>
<cl-cd data-idx="38">&nbsp; &nbsp; &nbsp; &nbsp; paWidth = papa.clientWidth,</cl-cd>
<cl-cd data-idx="39">&nbsp; &nbsp; &nbsp; &nbsp; paHeight = papa.clientHeight,</cl-cd>
<cl-cd data-idx="40">&nbsp; &nbsp; &nbsp; &nbsp; sonSize = player.clientWidth,</cl-cd>
<cl-cd data-idx="41">&nbsp; &nbsp; &nbsp; &nbsp; bodyWidth = <span class="tRed">document</span>.body.clientWidth,</cl-cd>
<cl-cd data-idx="42">&nbsp; &nbsp; &nbsp; &nbsp; bodyHeight = <span class="tRed">document</span>.body.clientHeight,</cl-cd>
<cl-cd data-idx="43">&nbsp; &nbsp; &nbsp; &nbsp; paOffset = {<span class="tBlue">x:</span> getOffsetPos(papa).x, <span class="tBlue">y:</span> getOffsetPos(papa).y};</cl-cd>
<cl-cd data-idx="44">&nbsp; &nbsp; <span class="tRed">document</span>.onmousemove = <span class="tBlue">function</span>(e) {</cl-cd>
<cl-cd data-idx="45">&nbsp; &nbsp; &nbsp; &nbsp; clearTimeout(movTimer);</cl-cd>
<cl-cd data-idx="46">&nbsp; &nbsp; &nbsp; &nbsp; movTimer = setTimeout(<span class="tBlue">function</span>() {</cl-cd>
<cl-cd data-idx="47">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="tBlue">if</span>(e.target.<span class="tRed">id</span> === <span class="tMagenta">"player"</span>) <span class="tBlue">return</span>;</cl-cd>
<cl-cd data-idx="48">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="tBlue">if</span>(<span class="tRed">document</span>.fullscreenElement === null) {</cl-cd>
<cl-cd data-idx="49">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="tBlue">let</span> x = e.pageX, y = e.pageY;</cl-cd>
<cl-cd data-idx="50">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="tBlue">if</span>(x &lt; paOffset.x) x = paOffset.x;</cl-cd>
<cl-cd data-idx="51">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="tBlue">if</span>(y &lt; paOffset.y) y = paOffset.y;</cl-cd>
<cl-cd data-idx="52">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x = x - paOffset.x;</cl-cd>
<cl-cd data-idx="53">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y = y - paOffset.y;</cl-cd>
<cl-cd data-idx="54">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="tBlue">if</span>(x + sonSize &gt;= paWidth) x = paWidth - sonSize;</cl-cd>
<cl-cd data-idx="55">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="tBlue">if</span>(y + sonSize &gt;= paHeight) y = paHeight - sonSize;</cl-cd>
<cl-cd data-idx="56">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; player.style.cssText += `<span class="tBlue">left:</span> ${x}px; <span class="tBlue">top:</span> ${y}px`;</cl-cd>
<cl-cd data-idx="57">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } <span class="tBlue">else</span> {</cl-cd>
<cl-cd data-idx="58">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="tBlue">let</span> xx = e.offsetX || e.layerX, yy = e.offsetY || e.layerY;</cl-cd>
<cl-cd data-idx="59">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="tBlue">if</span>(xx + sonSize &gt; bodyWidth) xx -= sonSize;</cl-cd>
<cl-cd data-idx="60">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="tBlue">if</span>(yy + sonSize &gt; bodyHeight) yy -= sonSize;</cl-cd>
<cl-cd data-idx="61">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; player.style.cssText += `<span class="tBlue">left:</span> ${xx}px; <span class="tBlue">top:</span> ${yy}px`;</cl-cd>
<cl-cd data-idx="62">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</cl-cd>
<cl-cd data-idx="63">&nbsp; &nbsp; &nbsp; &nbsp; }, 400);</cl-cd>
<cl-cd data-idx="64">&nbsp; &nbsp; };</cl-cd>
<cl-cd data-idx="65">})();</cl-cd>
<cl-cd data-idx="66">&lt;<span class="tDarkRed">/script</span>&gt;</cl-cd>
</div>

马黑黑 发表于 2024-3-7 13:01

本帖最后由 马黑黑 于 2024-3-7 13:10 编辑

与 致敬女神节·知音 - 第3页 - 动画音画 - 花潮论坛 - Powered by Discuz! (huachaowang.com) 相比,这个:

① 播放控制器能够响应帖子外鼠标指针悬停动作;
② 加入了《知音》未作处理的全屏模式下的鼠标悬停响应机制。

本帖在新版Edg、Chromium、Firefox下测试通过,不知道其他较低内核的浏览器下表现如何。不支持IE。

小辣椒 发表于 2024-3-7 13:16

哇塞,这个播放器效果可以自动的漂移

小辣椒 发表于 2024-3-7 13:17

播放控制器能够响应帖子外鼠标指针悬停动作{:4_199:}

小辣椒 发表于 2024-3-7 13:18

黑黑玩的效果越来越美了,更加多样化了

马黑黑 发表于 2024-3-7 13:33

小辣椒 发表于 2024-3-7 13:16
哇塞,这个播放器效果可以自动的漂移

也不是自动。和《知音》差不多,只不过它能在帖子外围可以响应鼠标指针的悬停动作

小辣椒 发表于 2024-3-7 13:41

马黑黑 发表于 2024-3-7 13:33
也不是自动。和《知音》差不多,只不过它能在帖子外围可以响应鼠标指针的悬停动作

我来不及测试了,本来想自己电脑做一个试试,先下了

马黑黑 发表于 2024-3-7 13:46

小辣椒 发表于 2024-3-7 13:41
我来不及测试了,本来想自己电脑做一个试试,先下了

不急的慢慢来

红影 发表于 2024-3-7 15:46

“它能在帖子外围可以响应鼠标指针的悬停动作”
果然如此呢,而且跟全屏图标也不相冲了。
画面制作很是清爽舒服呢{:4_199:}

红影 发表于 2024-3-7 15:47

黑黑一直在不断钻研细节的东东,很赞{:4_199:}

马黑黑 发表于 2024-3-7 17:22

红影 发表于 2024-3-7 15:46
“它能在帖子外围可以响应鼠标指针的悬停动作”
果然如此呢,而且跟全屏图标也不相冲了。
画面制作很是清 ...

感谢点评。

全屏时,鼠标指针悬停在全屏开关按钮会“驱逐”播放器按钮,非全屏是不会。这是特意设计的。

马黑黑 发表于 2024-3-7 17:23

红影 发表于 2024-3-7 15:47
黑黑一直在不断钻研细节的东东,很赞

也不是一直,有心情的时候,比如钓鱼时,琢磨琢磨。杀猪时要全身投入,就不能思考这类问题了。

南无月 发表于 2024-3-7 17:44

这个小播跟个小盆友似的。。。全屏状把小播引到边上~~退出全屏的时候,小播会在贴子外面慢吞吞跑贴子里来。{:4_173:}

马黑黑 发表于 2024-3-7 17:58

南无月 发表于 2024-3-7 17:44
这个小播跟个小盆友似的。。。全屏状把小播引到边上~~退出全屏的时候,小播会在贴子外面慢吞吞跑贴子里来。 ...

这也被你发现了

千羽 发表于 2024-3-7 19:22

这个小树播放器精力好充沛,像个淘气包……给黑黑老师点赞送花花来了{:4_187:}{:4_199:}

马黑黑 发表于 2024-3-7 19:23

千羽 发表于 2024-3-7 19:22
这个小树播放器精力好充沛,像个淘气包……给黑黑老师点赞送花花来了

谢花花

绿叶清舟 发表于 2024-3-7 19:46

这个就是射程自由吗

马黑黑 发表于 2024-3-7 19:47

绿叶清舟 发表于 2024-3-7 19:46
这个就是射程自由吗

也许吧,我也不太清楚

绿叶清舟 发表于 2024-3-7 19:48

马黑黑 发表于 2024-3-7 19:47
也许吧,我也不太清楚

不是你说的嘛
页: [1] 2 3 4 5 6
查看完整版本: Lost in Time