马黑黑 发表于 2022-6-21 19:21

前路(测试range播放器)

本帖最后由 马黑黑 于 2022-6-21 19:40 编辑 <br /><br /><style>
.papa { left: -214px; width: 1024px; height: 576px; background: rgba(0,0,0,.4) url('/data/attachment/forum/202206/21/191857w3zwdm3m739fy44r.jpg') no-repeat center/cover; overflow: hidden; position: relative; }
.papa input { border: none; outline: none; opacity: .75; cursor: pointer; }
.papa p { margin: 0; padding: 0; }
.playbox { position: relative; left: 10px; top: 10px; padding: 10px; width: fit-content; font: normal 1em sans-serif; color: snow; background: transparent;border-radius: 8px; overflow: hidden; box-shadow: 1px 1px 2px rgba(0,0,0,.15); z-index: 1; }
.playbox::before { position: absolute;content: '';margin: -20px;left: 0; top: 0; right: 0; bottom: 0;background: rgba(255,255,255,.45);filter: blur(2px); z-index: -1; }
#btnplay { width: 30px; height: 30px; border-radius: 50%; }
#btnplay:hover { background: #aaa; color: #ff0000; }
.vid { position: absolute; top: -55px; width: 1024px; height: 255px; object-fit: cover; opacity: 0.2; }
</style>

<div class="papa">
        <video class="vid" src="https://img.tukuppt.com/video_show/2475824/00/01/72/5b491e2dabd0f.mp4" autoplay="autoplay" loop="loop" muted="muted"></video>
        <div class="playbox">
                <p id="geci">LRC Loading ... </p>
                <p style="display: flex; align-items: center; gap: 4px; margin-top: 10px;">
                        <input id="btnplay" type="button" value=">" />
                        <input id="slider" type="range" min="0" max="100" value="0" />
                        <span id="per">0%</span>
                </p>
        </div>
        <audio id="aud" src="https://music.163.com/song/media/outer/url?id=28188157.mp3" autoplay="autoplay" loop="loop"></audio>
</div>

<script>

let slider = document.querySelector('#slider'),
        aud = document.querySelector('#aud'),
        per = document.querySelector('#per'),
        btnplay = document.querySelector('#btnplay'),
        geci = document.querySelector('#geci');
let slip = 0; //误差值
let lrcAr = [
        ['0.00','歌名:前路'],
        ['2.20','歌手:姚贝娜'],
        ['6.78','电视剧《女人不哭》主题曲'],
        ['9.45','当上天那样糊涂'],
        ['16.19','当命运那样残酷'],
        ['22.99','当对手那样可恶'],
        ['29.88','当时间那样仓促'],
        ['36.79','当是非如此模糊'],
        ['43.47','当爱恨如此庸俗'],
        ['50.46','当去留如此短促'],
        ['57.28','当生死如此孤独'],
        ['65.18','女人不哭'],
        ['70.88','不是因为她没有感触'],
        ['77.85','不是因为她不想得到爱护'],
        ['83.67','只是情仇恩怨喜乐悲苦成败得失'],
        ['89.68','都是一瞬间光顾'],
        ['95.70','女人不哭'],
        ['102.17','回头也没有退路'],
        ['108.91','傍徨也要开创前路'],
        ['114.08','只能勇敢迈步'],
        ['149.07','情糊涂人不糊涂'],
        ['155.77','命坎坷方向清楚'],
        ['162.62','让对手甘心佩服'],
        ['169.53','让时间随心跳动'],
        ['177.26','女人不哭'],
        ['183.51','回头也没有退路'],
        ['190.47','傍徨也要开创前路'],
        ['195.75','只能勇敢迈步'],
        ['203.78','女人不哭'],
        ['210.20','回头也没有退路'],
        ['217.00','傍徨也要开创前路'],
        ['222.27','只能勇敢迈步']
]

slider.onmousedown = () => aud.pause();
slider.onchange = () => { aud.currentTime = slider.value * aud.duration / 100; aud.play(); }
btnplay.onclick = () => aud.paused ? aud.play() : aud.pause();
aud.addEventListener('playing', () => btnplay.value = '||');
aud.addEventListener('pause', () => btnplay.value = '>');

aud.addEventListener('timeupdate', () => {
        let prog = 100 * aud.currentTime / aud.duration;
        slider.value = prog;
        per.innerText = prog.toFixed(2) + '%';
                for(j=0; j<lrcAr.length; j++){
                if(aud.currentTime >= lrcAr - slip){
                        geci.innerHTML = lrcAr;
                }
        }
});

</script>

马黑黑 发表于 2022-6-21 19:24

测试内容:

一、type 为 range 的 input 作为进度条的情况;

二、元素、伪元素均为 absolute 定位时 z-index 的表现;

三、真正的毛玻璃 lrc歌词+播放控制 效果

马黑黑 发表于 2022-6-21 19:24

参考代码:
<style>
.papa { left: -214px; width: 1024px; height: 576px; background: rgba(0,0,0,.4) url('/data/attachment/forum/202206/21/191857w3zwdm3m739fy44r.jpg') no-repeat center/cover; position: relative; }
.papa input { border: none; outline: none; opacity: .75; cursor: pointer; }
.papa p { margin: 0; padding: 0; }
.playbox { position: relative; left: 10px; top: 10px; padding: 10px; width: fit-content; font: normal 1em sans-serif; color: snow; background: transparent;border-radius: 8px; overflow: hidden; box-shadow: 1px 1px 2px rgba(0,0,0,.15); z-index: 1; }
.playbox::before { position: absolute;content: '';margin: -20px;left: 0; top: 0; right: 0; bottom: 0;background: rgba(255,255,255,.45);filter: blur(2px); z-index: -1; }
#btnplay { width: 30px; height: 30px; border-radius: 50%; }
#btnplay:hover { background: #aaa; color: #ff0000; }
.vid { position: absolute; top: -55px; width: 1024px; height: 255px; object-fit: cover; opacity: 0.2; }
</style>

<div class="papa">
        <video class="vid" src="https://img.tukuppt.com/video_show/2475824/00/01/72/5b491e2dabd0f.mp4" autoplay="autoplay" loop="loop" muted="muted"></video>
        <div class="playbox">
                <p id="geci">LRC Loading ... </p>
                <p style="display: flex; align-items: center; gap: 4px; margin-top: 10px;">
                        <input id="btnplay" type="button" value=">" />
                        <input id="slider" type="range" min="0" max="100" value="0" />
                        <span id="per">0%</span>
                </p>
        </div>
        <audio id="aud" src="https://music.163.com/song/media/outer/url?id=28188157.mp3" autoplay="autoplay" loop="loop"></audio>
</div>

<script>

let slider = document.querySelector('#slider'),
        aud = document.querySelector('#aud'),
        per = document.querySelector('#per'),
        btnplay = document.querySelector('#btnplay'),
        geci = document.querySelector('#geci');
let slip = 0; //误差值
let lrcAr = [
        ['0.00','歌名:前路'],
        ['2.20','歌手:姚贝娜'],
        ['6.78','电视剧《女人不哭》主题曲'],
        ['9.45','当上天那样糊涂'],
        ['16.19','当命运那样残酷'],
        ['22.99','当对手那样可恶'],
        ['29.88','当时间那样仓促'],
        ['36.79','当是非如此模糊'],
        ['43.47','当爱恨如此庸俗'],
        ['50.46','当去留如此短促'],
        ['57.28','当生死如此孤独'],
        ['65.18','女人不哭'],
        ['70.88','不是因为她没有感触'],
        ['77.85','不是因为她不想得到爱护'],
        ['83.67','只是情仇恩怨喜乐悲苦成败得失'],
        ['89.68','都是一瞬间光顾'],
        ['95.70','女人不哭'],
        ['102.17','回头也没有退路'],
        ['108.91','傍徨也要开创前路'],
        ['114.08','只能勇敢迈步'],
        ['149.07','情糊涂人不糊涂'],
        ['155.77','命坎坷方向清楚'],
        ['162.62','让对手甘心佩服'],
        ['169.53','让时间随心跳动'],
        ['177.26','女人不哭'],
        ['183.51','回头也没有退路'],
        ['190.47','傍徨也要开创前路'],
        ['195.75','只能勇敢迈步'],
        ['203.78','女人不哭'],
        ['210.20','回头也没有退路'],
        ['217.00','傍徨也要开创前路'],
        ['222.27','只能勇敢迈步']
]

slider.onmousedown = () => aud.pause();
slider.onchange = () => { aud.currentTime = slider.value * aud.duration / 100; aud.play(); }
btnplay.onclick = () => aud.paused ? aud.play() : aud.pause();
aud.addEventListener('playing', () => btnplay.value = '||');
aud.addEventListener('pause', () => btnplay.value = '>');

aud.addEventListener('timeupdate', () => {
        let prog = 100 * aud.currentTime / aud.duration;
        slider.value = prog;
        per.innerText = prog.toFixed(2) + '%';
                for(j=0; j<lrcAr.length; j++){
                if(aud.currentTime >= lrcAr - slip){
                        geci.innerHTML = lrcAr;
                }
        }
});

</script>

马黑黑 发表于 2022-6-21 19:25

除去歌词,JS部分的代码量并不大

加林森 发表于 2022-6-21 19:28

老黑制作得真完美。等会来学习。{:4_199:}

马黑黑 发表于 2022-6-21 19:33

关于真正的毛玻璃:

毛玻璃有透明度,但不是完全透明。CSS里,元素设置为背景一定的透明度,能产生一定的毛玻璃效果,不过不一定都是毛玻璃,可能是普通玻璃,一切依赖于背景图片的加持。真正的毛玻璃,透明中有浑浊度,浑浊中有透明度,就像win7任务条或窗口标题栏,以及苹果的界面元素效果。

所以,本帖播放界面的设计,与之前的不尽相同,用了一个伪元素做玻璃地板,加高斯模糊(这很重要,它是普通玻璃和毛玻璃的区别所在),置于主元素下方(因此用上z-index)。

马黑黑 发表于 2022-6-21 19:36

歌词能够被选择,说明 z-index 设置有效;

能看见播放控制区域气候的景象,说明透明处理有效;

播放控制区域有浑浊感,说明毛玻璃有效;

拖动播放进度条的球形滑块,能调整音乐进度,说明 range 工作正常。

马黑黑 发表于 2022-6-21 19:39

加林森 发表于 2022-6-21 19:28
老黑制作得真完美。等会来学习。

刚弄好,这就吃饭去了

绿叶清舟 发表于 2022-6-21 19:49

这个背景漂亮

加林森 发表于 2022-6-21 19:56

马黑黑 发表于 2022-6-21 19:39
刚弄好,这就吃饭去了

辛苦了!{:4_191:}

马黑黑 发表于 2022-6-21 19:59

绿叶清舟 发表于 2022-6-21 19:49
这个背景漂亮

背景图片,路挺好的

山人 发表于 2022-6-21 20:39

Chromium低版本下滑块是蓝色的,高版本,比如100,是黑灰色的

绿叶清舟 发表于 2022-6-21 20:47

马黑黑 发表于 2022-6-21 19:59
背景图片,路挺好的

有前途啊

红影 发表于 2022-6-21 20:52

漂亮。去拉了一下进度,都很正常,这个播放框漂亮{:4_187:}

红影 发表于 2022-6-21 20:52

制作很漂亮,欣赏黑黑好帖{:4_187:}

马黑黑 发表于 2022-6-21 21:12

红影 发表于 2022-6-21 20:52
制作很漂亮,欣赏黑黑好帖

蟹蟹3

马黑黑 发表于 2022-6-21 21:13

绿叶清舟 发表于 2022-6-21 20:47
有前途啊

所以叫前路

马黑黑 发表于 2022-6-21 21:13

红影 发表于 2022-6-21 20:52
漂亮。去拉了一下进度,都很正常,这个播放框漂亮

这个适应性可能会好一些

红影 发表于 2022-6-21 22:01

马黑黑 发表于 2022-6-21 21:12
蟹蟹3

还不少呢{:4_173:}

醉美水芙蓉 发表于 2022-6-21 22:01

页: [1] 2 3
查看完整版本: 前路(测试range播放器)