夕颜花
本帖最后由 马黑黑 于 2022-10-23 11:55 编辑 <br /><br /><style>#papa { left: -214px; width: 1024px; height: 640px; background: url('https://638183.freep.cn/638183/t22/webp/xiyjhx.webp') no-repeat center/cover; box-shadow: 3px 3px 20px #000; position: relative; display: grid; place-items: center; user-select: none; z-index: 1; --opt: .25;}
#papa::before { position: absolute; content: ''; width: 100%; height: 100%; background: url('https://638183.freep.cn/638183/t22/webp/124.gif') repeat; opacity: var(--opt); }
#mplayer { position: absolute; bottom: 0; z-index: 9; }
#lrc { --motion: cover1; --tt: 5s; --state: paused; position: absolute; top: 30px; font: bold 2.4em sans-serif; color: hsl(0,10%,90%); -webkit-background-clip: text; filter: drop-shadow(1px 1px 2px hsla(0,0%,0%,.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(280,100%,50%,.75),hsla(180,100%,50%,.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="360" height="60" style="user-select: none;">
<rect x="50" y="25" rx="6" ry="6" width="200" height="12" stroke="hsla(280,90%,55%,.45)" fill="hsla(60,100%,92%,.35)" id="track" />
<rect x="50" y="25" rx="6" ry="6" width="0" height="12" stroke="transparnet" fill="hsla(280,90%,55%,.45)" id="prog" />
<text x="260" y="31" font-size="14" dominant-baseline="middle" stroke="none" fill="tan" id="audtime">00:00 | 00:00</text>
<circle cx="25" cy="30" r="15" fill="url(#bgcolor)" id="btnplay" style="cursor: pointer;">
<animateTransform attributeName="transform" dur="3s" type="rotate" from="0 25 30" to="360 25 30" repeatCount="indefinite" />
</circle>
<defs>
<linearGradient x1="0%" y1="0%" x2="100%" y2="50%" id="bgcolor">
<stop offset="0%" style="stop-color: pink; stop-opacity:0.8" />
<stop offset="100%" style="stop-color: green; stop-opacity:0.75" />
</linearGradient>
</defs>
</svg>
</div>
<script>
(function() {
let mp = { len: track.getAttribute('width')*1, x: track.getAttribute('x')*1 }, aud = new Audio(), mKey = 0, mFlag = true;
let lrcAr = [,,,,,,,,,,,,,];
aud.src = 'https://music.163.com/song/media/outer/url?id=1973395208.mp3';
aud.loop = true;
aud.autoplay = true;
if(aud.paused) mplayer.pauseAnimations();
btnplay.onclick = () => aud.paused ? aud.play() : aud.pause();
prog.onclick = track.onclick = (e) => aud.currentTime = aud.duration * (e.offsetX - mp.x) / mp.len;
aud.addEventListener('seeked', () => calcKey());
aud.addEventListener('pause', () =>mState());
aud.addEventListener('play', () =>mState());
aud.addEventListener('timeupdate', () => {prog.style.setProperty('width', aud.currentTime * 200 / aud.duration + 'px');audtime.textContent = toMin(aud.currentTime) + ' | ' + toMin(aud.duration);for(j=0; j<lrcAr.length; j++) {if(aud.currentTime >= lrcAr) {cKey = j;if(mKey === j) showLrc(lrcAr);else continue;}}});
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 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 mState = () => aud.paused ? (mplayer.pauseAnimations(),lrc.style.setProperty('--state', 'paused'),papa.style.setProperty('--opt','0')) : (mplayer.unpauseAnimations(), lrc.style.setProperty('--state', 'running'),papa.style.setProperty('--opt','.25'));
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;}
})();
</script>
本帖,将 纯svg音频播放控制器 + 歌词同步,代码如下:
<style>
#papa { margin: auto; width: 1024px; height: 640px; background: url('https://638183.freep.cn/638183/t22/webp/xiyjhx.webp') no-repeat center/cover; box-shadow: 3px 3px 20px #000; position: relative; display: grid; place-items: center; user-select: none; z-index: 1; --opt: .25;}
#papa::before { position: absolute; content: ''; width: 100%; height: 100%; background: url('https://638183.freep.cn/638183/t22/webp/124.gif') repeat; opacity: var(--opt); }
#mplayer { position: absolute; bottom: 0; z-index: 9; }
#lrc { --motion: cover1; --tt: 5s; --state: paused; position: absolute; top: 30px; font: bold 2.4em sans-serif; color: hsl(0,10%,90%); -webkit-background-clip: text; filter: drop-shadow(1px 1px 2px hsla(0,0%,0%,.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(280,100%,50%,.75),hsla(180,100%,50%,.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="360" height="60" style="user-select: none;">
<rect x="50" y="25" rx="6" ry="6" width="200" height="12" stroke="hsla(280,90%,55%,.45)" fill="hsla(60,100%,92%,.35)" id="track" />
<rect x="50" y="25" rx="6" ry="6" width="0" height="12" stroke="transparnet" fill="hsla(280,90%,55%,.45)" id="prog" />
<text x="260" y="31" font-size="14" dominant-baseline="middle" stroke="none" fill="tan" id="audtime">00:00 | 00:00</text>
<text x="10" y="35" font-size="40" dominant-baseline="middle" stroke="tan" fill="purple" id="btnplay" style="cursor: pointer;">☀
<animateTransform attributeName="transform" dur="4s" type="rotate" from="0 26.86 30" to="360 26.86 30" repeatCount="indefinite" />
</text>
</svg>
</div>
<script>
(function() {
let mp = { len: track.getAttribute('width')*1, x: track.getAttribute('x')*1 }, aud = new Audio(), mKey = 0, mFlag = true;
let lrcAr = [,,,,,,,,,,,,,];
aud.src = 'https://music.163.com/song/media/outer/url?id=1973395208.mp3';
aud.loop = true;
aud.autoplay = true;
if(aud.paused) mplayer.pauseAnimations();
btnplay.onclick = () => aud.paused ? aud.play() : aud.pause();
prog.onclick = track.onclick = (e) => aud.currentTime = aud.duration * (e.offsetX - mp.x) / mp.len;
aud.addEventListener('seeked', () => calcKey());
aud.addEventListener('pause', () =>mState());
aud.addEventListener('play', () =>mState());
aud.addEventListener('timeupdate', () => {prog.style.setProperty('width', aud.currentTime * 200 / aud.duration + 'px');audtime.textContent = toMin(aud.currentTime) + ' | ' + toMin(aud.duration);for(j=0; j<lrcAr.length; j++) {if(aud.currentTime >= lrcAr) {cKey = j;if(mKey === j) showLrc(lrcAr);else continue;}}});
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 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 mState = () => aud.paused ? (mplayer.pauseAnimations(),lrc.style.setProperty('--state', 'paused'),papa.style.setProperty('--opt','0')) : (mplayer.unpauseAnimations(), lrc.style.setProperty('--state', 'running'),papa.style.setProperty('--opt','.25'));
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;}
})();
</script>
本帖最后由 马黑黑 于 2022-10-21 07:55 编辑
夕颜花,正式名称是月光花,爱为其花语。此花黄昏盛开,次晨凋零,喻消香玉损。
此歌,可推测属念故人之作。歌词简短,一唱三叹,在独特的配乐烘托下,将情感推入极深的境地。 svg rect+text 元素的播放器,在我的花园有一些解释,这里再补充几句:
用 rect 画出两个圆角矩形,一个做 track(轨道),一个做 prog(progress,进度),后者初始长度为0,由 audio 控件的播放进度改变它的长度(它连同track也可以反过来改变audio的播放进度)。有一个小小的缺陷:音乐播放之初,进度条的表现很丑,这是因为圆角和矩形宽度的比例问题——宽度极小时圆角呈现怪异。不过,黑不掩白,哦不,是瑕不掩瑜,整体,播放器还是很漂酿的。 这不是喇叭花吗?{:5_117:} 哇!好漂亮哎! 又是另外一种播放器了。{:4_199:} 加林森 发表于 2022-10-21 10:59
又是另外一种播放器了。
{:4_190:} 东篱闲人 发表于 2022-10-21 08:54
这不是喇叭花吗?
它们是亲戚 梦油 发表于 2022-10-21 09:05
哇!好漂亮哎!
还行的 马黑黑 发表于 2022-10-21 12:12
它们是亲戚
哦。{:5_117:} 东篱闲人 发表于 2022-10-21 12:31
哦。
甄嬛传里,是将喇叭花当做夕颜花的,而且,我看了一些荆楚旧时资料,可以印证的 播放器新颖好看,喜欢! 马黑黑 发表于 2022-10-21 12:49
甄嬛传里,是将喇叭花当做夕颜花的,而且,我看了一些荆楚旧时资料,可以印证的
你还是个生物学家。。。。。{:5_116:} 马黑黑 发表于 2022-10-21 12:12
还行的
你对自己要求的标准高啊 马黑黑 发表于 2022-10-21 12:10
谢谢! 加林森 发表于 2022-10-21 16:21
谢谢!
客气客气 梦油 发表于 2022-10-21 15:52
你对自己要求的标准高啊
一般般的不高 东篱闲人 发表于 2022-10-21 15:18
你还是个生物学家。。。。。
研究方向是生命心理学 相约爱晚亭 发表于 2022-10-21 14:36
播放器新颖好看,喜欢!
{:5_108:}