红影 发表于 2022-10-14 19:10

《孤城》(学习黑黑SVG文本特效)

<style>
#papa { left: -302px; width: 1200px; height: 675px; background: snow url('https://pic1.imgdb.cn/item/6348c23f16f2c2beb1427f8c.jpg') no-repeat center/cover; display: grid; place-items: center; box-shadow: 3px 3px 20px #000; user-select: none; position: relative; }
#mplayer { position: absolute; bottom: 20px; left:20px; width: 240px; height: 60px; font: normal 14px sans-serif; }
#mplayer::before, #mplayer::after { position: absolute; width: 100%; height: 50%; color: snow; margin: 15px 0; }
#mplayer::before { content: attr(data-cur); }
#mplayer::after { content: attr(data-dur); text-align: right; }
#btnplay { position: absolute; left: calc(50% - 15px); bottom: 25px; width: 30px; height: 30px; border-radius: 50%; background: conic-gradient(red, magenta, blue, aqua, lime, yellow, red); cursor: pointer; z-index: 2; animation: rot linear 4s infinite; }
#prog { --posX: 0px; position: absolute; bottom: 10px; width: 100%; height: 1px; background: #eee; cursor: pointer; }
#prog::before, #prog::after { position: absolute; content: ''; left: 0; }
#prog::before { width: var(--posX); height: 1px; background: red; }
#prog::after { left: var(--posX); top: calc(50% - 6px); width: 3px; height: 10px;background: silver; }
#lrc { --motion: cover1; --tt: 5s; --state: paused; position: absolute; bottom: 20px; font: bold 2.4em sans-serif; color: hsl(0,10%,90%); -webkit-background-clip: text; filter: drop-shadow(1px 1px 2px hsla(0,100%,0%,.85)); }
#lrc::before { position: absolute; content: attr(data-lrc); width: 20%; height: 100%; color: transparent; overflow: hidden; white-space: nowrap; background: linear-gradient(180deg,hsla(28,15%,90%,.55),hsla(22,62%,50%,.95)); filter: inherit; -webkit-background-clip: text; animation: var(--motion) var(--tt) linear forwards; animation-play-state: var(--state); }
#svg { position: absolute; left:580px; top:80px; font: bold 8em serif; }
.text { fill: hsla(21,70%,36%,.1); stroke-width: 3; stroke-dasharray: 0 300; stroke-dashoffset: 0; }
.text:nth-child(3n + 1) { stroke: hsl(28, 100%, 77%); animation: stroke1 30s ease-in-out infinite alternate; }
.text:nth-child(3n + 2) { stroke: hsl(28, 100%, 59%); animation: stroke2 30s ease-in-out infinite alternate; }
.text:nth-child(3n + 3) { stroke: hsl(28, 100%, 27%); animation: stroke3 30s ease-in-out infinite alternate; }
.text:hover { fill: rgb(156, 73, 28); opacity: .75; }
.yan { position: absolute; width: 451px; height: 249px; top:2px; right:10px;}
.renwu { position: absolute; width: 58px; height: 186px; bottom: 44px; left: 400px; animation: walk 42s linear infinite;}
@keyframes walk {
      0% { transform: rotate(-1deg) scale(1); left: 400px; bottom:40px;}
      10% { transform: rotate(0deg) scale(0.92); left: 402px; bottom:46px; }
      20% { transform: rotate(1deg) scale(0.84); left: 405px; bottom:52px; }
      30% { transform: rotate(0deg) scale(0.76); left: 407px; bottom:58px; }
      40% { transform: rotate(-1deg) scale(0.68); left: 410px; bottom:64px; }
      50%{ transform: rotate(0deg) scale(0.6); left: 412px; bottom:64px; }
      60%{ transform: rotate(1deg) scale(0.52); left: 415px; bottom:64px; }
      70%{ transform: rotate(0deg) scale(0.44); left: 417px; bottom:68px; }
      80%{ transform: rotate(-1deg) scale(0.36); left: 410px; bottom:72px; }
      90%{ transform: rotate(0deg) scale(0.28); left: 402px; bottom:76px; }
      100%{ transform: rotate(0deg) scale(0.2); left:395px; bottom:80px; } }
@keyframes stroke1 { to { stroke-dashoffset: 1000; stroke-dasharray: 80 160; } }
@keyframes stroke2 { to { stroke-dashoffset: 1080; stroke-dasharray: 80 160; } }
@keyframes stroke3 { to { stroke-dashoffset: 1160; stroke-dasharray: 80 160; } }
@keyframes cover1 { from { width: 0; } to { width: 100%; } }
@keyframes cover2 { from { width: 0; } to { width: 100%; } }
@keyframes rot { to { transform: rotate(1turn); } }
</style>
<div id="papa">
      <img class="yan" src="https://pic1.imgdb.cn/item/62479cbe27f86abb2adbb9bd.gif" alt="" />
                <img class="renwu" src="https://pic1.imgdb.cn/item/6348e8a916f2c2beb179d4e9.png" alt="" />
        <svg id="svg" width="500" height="300">
                <symbol id="s-text"><text text-anchor="middle"x="50%" y="50%" dy=".35em">孤城</text></symbol>
                <use xlink:href="#s-text" class="text"></use>
                <use xlink:href="#s-text" class="text"></use>
                <use xlink:href="#s-text" class="text"></use>
        </svg>
      <div id="lrc" data-lrc="花潮lrc在线">花潮lrc在线</div>
      <div id="mplayer" data-cur="00:00" data-dur="00:00"><span id="prog"></span><span id="btnplay"></span></div>
</div>
<script>
let mKey = 0, mFlag = true, aud = new Audio();
let lrcAr = [
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
       
];
aud.src = 'https://music.163.com/song/media/outer/url?id=132993.mp3';
aud.autoplay = true;
aud.loop = true;
if(aud.paused) btnplay.style.animationPlayState = 'paused';
btnplay.onclick = () => aud.paused ? aud.play() : aud.pause();
mplayer.onmousemove = (e) => { mplayer.style.cursor = e.offsetY > mplayer.offsetHeight / 1.5 ? 'pointer' : 'default'; }
mplayer.onclick =(e) => { if(e.offsetY > mplayer.offsetHeight / 1.5) aud.currentTime = aud.duration * e.offsetX / prog.offsetWidth; }
aud.addEventListener('pause', () => mState());
aud.addEventListener('play', () => mState());
aud.addEventListener('seeked', () => calcKey());
aud.addEventListener('timeupdate', () => { prog.style.setProperty('--posX', prog.offsetWidth * aud.currentTime / aud.duration + 'px'); mplayer.dataset.cur = toMin(aud.currentTime); mplayer.dataset.dur = 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.animationPlayState = 'paused', lrc.style.setProperty('--state', 'paused')) : (btnplay.style.animationPlayState ='running', 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; };
papa.oncontextmenu = () => false;
</script>

红影 发表于 2022-10-14 19:19

忽然想起一首以前听过的歌,也想起听错的歌词,那句“放眼望去却有太多聪明人”,被我听成了“放眼望去却有太多崇明人”,当时就觉得奇怪,崇明乌小蟹关孤城什么事,要孤也是岛啊{:4_173:}

红影 发表于 2022-10-14 19:21

学着用hsl调颜色,把动态字的颜色都用一种颜色的不同灰度来处理了,觉得更接近的颜色比较不突兀。
感谢黑黑的代码{:4_187:}

起个网名好难 发表于 2022-10-14 19:56

本帖最后由 起个网名好难 于 2022-10-14 20:16 编辑

学习、欣赏!

梦油 发表于 2022-10-14 20:10

天空飞舞的小燕子和“孤城”两个字设计得太美了,画面的色调也与“孤城”的意境相得益彰。

红影 发表于 2022-10-14 20:23

起个网名好难 发表于 2022-10-14 19:56
学习、欣赏!

谢谢,感谢临帖鼓励{:4_187:}

上海朝阳 发表于 2022-10-14 20:24

红影 发表于 2022-10-14 19:19
忽然想起一首以前听过的歌,也想起听错的歌词,那句“放眼望去却有太多聪明人”,被我听成了“放眼望去却有 ...

哈哈,侬也会崇明话啊

红影 发表于 2022-10-14 20:26

梦油 发表于 2022-10-14 20:10
天空飞舞的小燕子和“孤城”两个字设计得太美了,画面的色调也与“孤城”的意境相得益彰。

这个动画字是黑黑的代码弄的,这个帖子最麻烦的是那个人,我想让静态的人动起来,结果控制不好位置,走着走着就不对了,折腾半天{:4_189:}

相约爱晚亭 发表于 2022-10-14 20:27

欣赏佳作!

梦油 发表于 2022-10-14 20:38

红影 发表于 2022-10-14 20:26
这个动画字是黑黑的代码弄的,这个帖子最麻烦的是那个人,我想让静态的人动起来,结果控制不好位置,走着 ...

人倒是走起来了,但效果稍差一点。

马黑黑 发表于 2022-10-14 22:13

红影 发表于 2022-10-14 19:19
忽然想起一首以前听过的歌,也想起听错的歌词,那句“放眼望去却有太多聪明人”,被我听成了“放眼望去却有 ...

所有的代码都有所改进,这是根据帖意而作出的构思与编辑,非常不错

红影 发表于 2022-10-14 22:23

上海朝阳 发表于 2022-10-14 20:24
哈哈,侬也会崇明话啊

我不会啊,我只是觉得当初听错的错法特别好玩{:4_173:}

红影 发表于 2022-10-14 22:24

相约爱晚亭 发表于 2022-10-14 20:27
欣赏佳作!

谢谢爱晚亭鼓励{:4_204:}

红影 发表于 2022-10-14 22:24

梦油 发表于 2022-10-14 20:38
人倒是走起来了,但效果稍差一点。

嗯嗯,下回还是换个动图的,可能会好点{:4_173:}

红影 发表于 2022-10-14 22:27

马黑黑 发表于 2022-10-14 22:13
所有的代码都有所改进,这是根据帖意而作出的构思与编辑,非常不错

谢谢黑黑的鼓励,也差不多基本上是套用代码呢,都是从你的帖子里来的代码{:4_173:}

马黑黑 发表于 2022-10-14 22:33

红影 发表于 2022-10-14 22:27
谢谢黑黑的鼓励,也差不多基本上是套用代码呢,都是从你的帖子里来的代码

民谚说的好:天下代码一大抄,就看抄者咋操刀{:4_170:}

红影 发表于 2022-10-14 22:47

马黑黑 发表于 2022-10-14 22:33
民谚说的好:天下代码一大抄,就看抄者咋操刀

有这样的民谚么,又是你自己弄的吧{:4_173:}

马黑黑 发表于 2022-10-14 22:51

红影 发表于 2022-10-14 22:47
有这样的民谚么,又是你自己弄的吧

有的有的,有空查查看

红影 发表于 2022-10-15 08:02

起个网名好难 发表于 2022-10-14 19:56
学习、欣赏!

看到你这个签名图,不禁笑,我开始去理解HSL时也是先看的这张图图。
这个颜色的表达特别好,很科学。

红影 发表于 2022-10-15 08:04

马黑黑 发表于 2022-10-14 22:51
有的有的,有空查查看

这首歌是很早以前手机里的循环,我忘了歌名,因为做帖子,竟然找出来了以前喜欢的一首歌。这也算是学习代码的额外收获吧{:4_173:}
页: [1] 2 3
查看完整版本: 《孤城》(学习黑黑SVG文本特效)