荒岛
<style>#papa { left: -214px; width: 1024px; height: 640px; background: url('https://638183.freep.cn/638183/Pic/81/zcool.webp') no-repeat 60px -140px/cover, url('https://638183.freep.cn/638183/Pic/81/8-4.webp') no-repeat center/cover; background-blend-mode: darken, saturation; box-shadow: 3px 3px 20px #000; display: grid; place-items: center; user-select: none; position: relative; z-index: 1; }
#mplayer { position: absolute; left: 160px; bottom: 10px; }
#btnwrap { display: block; fill: hsla(30, 20%, 80%, .9); cursor: pointer; }
#btnwrap:hover { fill: hsla(30, 100%, 50%, .9); }
#tmsg { fill: hsla(30, 0%, 50%, .9); stroke: none; font: bold 1em sans-serif; }
#lrc { --motion: cover1; --tt: 5s; --state: paused; position: absolute; left: 300px; bottom: 25px; font: bold 2.4em sans-serif; color: hsl(30,50%,90%); -webkit-background-clip: text; filter: drop-shadow(1px 1px 2px hsla(30,10%,10%,.95)); }
#lrc::before { position: absolute; content: attr(data-lrc); width: 20%; height: 100%; color: transparent; overflow: hidden; white-space: nowrap; background: linear-gradient(180deg,hsla(30,0%,0%,.95),hsla(30,0%,100%,.75)); filter: inherit; -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>
<div id="papa">
<div id="lrc" data-lrc="花潮论坛lrc在线">花潮论坛lrc在线</div>
<svg id="mplayer" width="120" height="120">
<g id="mama" transform="rotate(-90, 60, 60)" style="cursor: pointer;">
<circle id="track" cx="60" cy="60" r="50" fill="none" stroke-width="10" stroke="hsla(30, 20%, 80%, .9)" />
<circle id="prog" cx="60" cy="60" r="50" fill="none" stroke-width="6" stroke="hsla(30, 20%, 40%, .9)" />
</g>
<g id="btnwrap">
<path id="btnplay" d="M 50 50,50 70,70, 60 z"></path>
<path id="btnpause" d="M 52 50,52 70,57 70,57 50,52 50 z M 60 50,60 70,65 70,65 50,60 50 z"></path>
<path d="M 57 50,60 50,60 70,57 70 z" fill="transparent" />
</g>
<path id="curPath" d="M 20 70 Q 60 0 100 70" fill="none" stroke="none"/>
<path id="durPath" d="M 20 55 Q 60 110 100 55" fill="none" stroke="none"/>
<g id="tmsg">
<text x="34" y="0"><textPath id="curMsg" xlink:href="#curPath" dominant-baseline="text-after-edge">00:00</textPath></text>
<text x="29" y="0"><textPath id="durMsg" xlink:href="#durPath" dominant-baseline="text-before-edge">00:00</textPath></text>
</g>
</svg>
</div>
<script>
let mKey = 0, mSeek = false, mFlag = true, aud = new Audio();
let lrcAr = [,,,,,有一條路通向你的心",4.6],,,,,,,,,,,,,,了音訊的書信",5.4],,有人能帶著我逃離",4.4],,,,,,,,,,,,,,,,,,,,];
let cc = { x: 1*track.getAttribute('cx'), y: 1*track.getAttribute('cy'), len: track.getTotalLength(),};
prog.style.strokeDasharray = prog.style.strokeDashoffset =cc.len;
aud.src = 'https://music.163.com/song/media/outer/url?id=412319476.mp3';
aud.autoplay = true;
aud.loop = true;
btnwrap.onclick = () => aud.paused ? aud.play() : aud.pause();
mama.onclick = (e) => {
let deg = Math.atan2(e.offsetY - cc.y, e.offsetX - cc.x) * 180 / Math.PI;
deg += (e.offsetX < cc.x && e.offsetY < cc.y) ? 450 : 90;
aud.currentTime = aud.duration * deg / 360;
};
aud.addEventListener('pause', () => mState());
aud.addEventListener('play', () => mState());
aud.addEventListener('seeked', () => calcKey());
aud.addEventListener('timeupdate', () => {prog.style.strokeDashoffset = cc.len - cc.len * aud.currentTime / aud.duration;curMsg.textContent = toMin(aud.currentTime);durMsg.textContent = toMin(aud.duration);for(j=0; j<lrcAr.length; j++) {if(aud.currentTime >= lrcAr) {if(mKey === j) showLrc(lrcAr);else continue;}}});
let mState = () => aud.paused ? (btnplay.style.display = 'block', btnpause.style.display = 'none', lrc.style.setProperty('--state', 'paused')) : (btnplay.style.display = 'none', btnpause.style.display = 'block', lrc.style.setProperty('--state', 'running'));
let showLrc = (time) => {let name = mFlag ? 'cover1' : 'cover2';lrc.innerHTML = lrc.dataset.lrc = lrcAr;lrc.style.setProperty('--motion', name);lrc.style.setProperty('--tt', time + 's');lrc.style.setProperty('--state', 'running');mKey += 1;mFlag = !mFlag;};
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;};
mState();
</script>
帖子代码没有很特别的东东:
<style>
#papa { left: -214px; width: 1024px; height: 640px; background: url('https://638183.freep.cn/638183/Pic/81/zcool.webp') no-repeat 60px -140px/cover, url('https://638183.freep.cn/638183/Pic/81/8-4.webp') no-repeat center/cover; background-blend-mode: darken, saturation; box-shadow: 3px 3px 20px #000; display: grid; place-items: center; user-select: none; position: relative; z-index: 1; }
#mplayer { position: absolute; left: 160px; bottom: 10px; }
#btnwrap { display: block; fill: hsla(30, 20%, 80%, .9); cursor: pointer; }
#btnwrap:hover { fill: hsla(30, 100%, 50%, .9); }
#tmsg { fill: hsla(30, 0%, 50%, .9); stroke: none; font: bold 1em sans-serif; }
#lrc { --motion: cover1; --tt: 5s; --state: paused; position: absolute; left: 300px; bottom: 25px; font: bold 2.4em sans-serif; color: hsl(30,50%,90%); -webkit-background-clip: text; filter: drop-shadow(1px 1px 2px hsla(30,10%,10%,.95)); }
#lrc::before { position: absolute; content: attr(data-lrc); width: 20%; height: 100%; color: transparent; overflow: hidden; white-space: nowrap; background: linear-gradient(180deg,hsla(30,0%,0%,.95),hsla(30,0%,100%,.75)); filter: inherit; -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>
<div id="papa">
<div id="lrc" data-lrc="花潮论坛lrc在线">花潮论坛lrc在线</div>
<svg id="mplayer" width="120" height="120">
<g id="mama" transform="rotate(-90, 60, 60)" style="cursor: pointer;">
<circle id="track" cx="60" cy="60" r="50" fill="none" stroke-width="10" stroke="hsla(30, 20%, 80%, .9)" />
<circle id="prog" cx="60" cy="60" r="50" fill="none" stroke-width="6" stroke="hsla(30, 20%, 40%, .9)" />
</g>
<g id="btnwrap">
<path id="btnplay" d="M 50 50,50 70,70, 60 z"></path>
<path id="btnpause" d="M 52 50,52 70,57 70,57 50,52 50 z M 60 50,60 70,65 70,65 50,60 50 z"></path>
<path d="M 57 50,60 50,60 70,57 70 z" fill="transparent" />
</g>
<path id="curPath" d="M 20 70 Q 60 0 100 70" fill="none" stroke="none"/>
<path id="durPath" d="M 20 55 Q 60 110 100 55" fill="none" stroke="none"/>
<g id="tmsg">
<text x="34" y="0"><textPath id="curMsg" xlink:href="#curPath" dominant-baseline="text-after-edge">00:00</textPath></text>
<text x="29" y="0"><textPath id="durMsg" xlink:href="#durPath" dominant-baseline="text-before-edge">00:00</textPath></text>
</g>
</svg>
</div>
<script>
let mKey = 0, mSeek = false, mFlag = true, aud = new Audio();
let lrcAr = [,,,,,有一條路通向你的心",4.6],,,,,,,,,,,,,,了音訊的書信",5.4],,有人能帶著我逃離",4.4],,,,,,,,,,,,,,,,,,,,];
let cc = { x: 1*track.getAttribute('cx'), y: 1*track.getAttribute('cy'), len: track.getTotalLength(),};
prog.style.strokeDasharray = prog.style.strokeDashoffset =cc.len;
aud.src = 'https://music.163.com/song/media/outer/url?id=412319476.mp3';
aud.autoplay = true;
aud.loop = true;
btnwrap.onclick = () => aud.paused ? aud.play() : aud.pause();
mama.onclick = (e) => {
let deg = Math.atan2(e.offsetY - cc.y, e.offsetX - cc.x) * 180 / Math.PI;
deg += (e.offsetX < cc.x && e.offsetY < cc.y) ? 450 : 90;
aud.currentTime = aud.duration * deg / 360;
};
aud.addEventListener('pause', () => mState());
aud.addEventListener('play', () => mState());
aud.addEventListener('seeked', () => calcKey());
aud.addEventListener('timeupdate', () => {prog.style.strokeDashoffset = cc.len - cc.len * aud.currentTime / aud.duration;curMsg.textContent = toMin(aud.currentTime);durMsg.textContent = toMin(aud.duration);for(j=0; j<lrcAr.length; j++) {if(aud.currentTime >= lrcAr) {if(mKey === j) showLrc(lrcAr);else continue;}}});
let mState = () => aud.paused ? (btnplay.style.display = 'block', btnpause.style.display = 'none', lrc.style.setProperty('--state', 'paused')) : (btnplay.style.display = 'none', btnpause.style.display = 'block', lrc.style.setProperty('--state', 'running'));
let showLrc = (time) => {let name = mFlag ? 'cover1' : 'cover2';lrc.innerHTML = lrc.dataset.lrc = lrcAr;lrc.style.setProperty('--motion', name);lrc.style.setProperty('--tt', time + 's');lrc.style.setProperty('--state', 'running');mKey += 1;mFlag = !mFlag;};
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;};
mState();
</script>
主要是尝试双背景图片的运用。CSS3支持多图片的background属性设置,本帖,#papa 选择器使用了两个背景图片,一个有定位,另一个全覆盖:
background: url('https://638183.freep.cn/638183/Pic/81/zcool.webp') no-repeat 60px -140px/cover, url('https://638183.freep.cn/638183/Pic/81/8-4.webp') no-repeat center/cover;
两张张图片都设定 no-repeat,背景不平铺、以原本样子展开。其他属性,第一张,有菇凉的那幅图,60px -140px/cover,60px -140px 是定位,cover 属于背景大小参数关键字,这里是让图片以特定方式完好呈现的值(之前解释过);第二张,center/cover,center也是定位,图片居中展开,cover与第一张同,以一定的缩放比例呈现底图,底图不会因挤压而变形。
但,这样设定后,两张图片重合的区域里,第一张会覆盖第二张,因此,需要加入 background-blend-mode 混合滤镜:
background-blend-mode: darken, saturation;
这里,两张图片都是用了混合滤镜(混合滤镜在后花园有过介绍,感兴趣的可以搜索一下)。
顺便提一下,本帖图片,我都是用 .webp 格式的图片。这是谷歌格式的图片,质量与 jpg、jpeg 同,但明显比它们更轻盈小巧。昨天我加工的这张图,保存为 png 格式,原始文件 62.5 Kb:
https://www.huachaowang.com/data/attachment/forum/202210/03/190218nn44vrjromgj740p.png
存为 wepb 格式后,图片质量不变,文件大小仅为 3.36KB!
所以,建议论坛长传文件能支持 .webp 图片格式。
新颖的播放器,欣赏代码音画佳作! 马黑黑 发表于 2022-10-4 08:12
顺便提一下,本帖图片,我都是用 .webp 格式的图片。这是谷歌格式的图片,质量与 jpg、jpeg 同,但明显比它 ...
哦。我去看看设置。。。 马黑黑 发表于 2022-10-4 08:12
顺便提一下,本帖图片,我都是用 .webp 格式的图片。这是谷歌格式的图片,质量与 jpg、jpeg 同,但明显比它 ...
好主意!以后保存图片时试试。不知.webp格式图片能否通用 相约爱晚亭 发表于 2022-10-4 09:37
好主意!以后保存图片时试试。不知.webp格式图片能否通用
PS最新版本直接支持 .webp,其他版本需要弄个插件(网上找找) 红影 发表于 2022-10-4 09:33
哦。我去看看设置。。。
有劳管理员{:5_105:} 相约爱晚亭 发表于 2022-10-4 09:23
新颖的播放器,欣赏代码音画佳作!
这个播放器用 svg 做成,svg做起来有点略微复杂,但JS控制它简洁,主要是,圆形的东东,svg做的锯齿不严重 马黑黑 发表于 2022-10-4 08:06
主要是尝试双背景图片的运用。CSS3支持多图片的background属性设置,本帖,#papa 选择器使用了两个背景图片 ...
这两张混合起来,觉得更有味道了呢,比之前的两个单张好太多。黑黑很有美感{:4_199:} 马黑黑 发表于 2022-10-4 09:49
PS最新版本直接支持 .webp,其他版本需要弄个插件(网上找找)
又长见识了,PS需要个什么插件才能保存为.webp格式图片?谢谢! 马黑黑 发表于 2022-10-4 09:50
这个播放器用 svg 做成,svg做起来有点略微复杂,但JS控制它简洁,主要是,圆形的东东,svg做的锯齿不严 ...
我只会套用代码做帖,其他的心有余而力不足,没兴趣去深究。 这个歌词颜色又是同一种色相下的不同灰度和亮度的调整,漂亮{:4_187:} 红影 发表于 2022-10-4 10:01
这个歌词颜色又是同一种色相下的不同灰度和亮度的调整,漂亮
色相在这里不重要,它们基本没有出现本色(除了播放暂停按钮) 红影 发表于 2022-10-4 09:54
这两张混合起来,觉得更有味道了呢,比之前的两个单张好太多。黑黑很有美感
这类混合,实在是多靠运气 相约爱晚亭 发表于 2022-10-4 09:58
我只会套用代码做帖,其他的心有余而力不足,没兴趣去深究。
没关系,不同的需求,不同的做法 相约爱晚亭 发表于 2022-10-4 09:54
又长见识了,PS需要个什么插件才能保存为.webp格式图片?谢谢!
包括打开 webp 图片 马黑黑 发表于 2022-10-4 10:06
这类混合,实在是多靠运气
前一张可用粒子动态png图片,后静态或者动态都可以!效果超美,经常用的。 亚伦影音工作室 发表于 2022-10-4 13:43
前一张可用粒子动态png图片,后静态或者动态都可以!效果超美,经常用的。
你这是经验之谈了