傻得很潇洒(学习黑黑网格布局制作)
<style>/* 帖子父盒子 */
.mainBox {
left: -414px;
width: 1400px;
height: 800px;
top: 150px;
display: grid; /* 定义网格布局 */
grid-template-rows: 1fr 4fr 1fr; /* 帖子划分三行,高度六等分 :首尾两行个一个等分,中间行四个等分 */
grid-template-columns: repeat(3, 33.3%); /* 帖子划分三列,宽度三等分 */
background: lightblue url('https://wj.zp68.com/lxx/yunhua/2022/10/17/GIF.gif') no-repeat center/cover;
box-shadow: 3px 3px 20px #000;
position: relative;
z-index: 1;
}
/* 帖子直系div元素统一样式 */
.mainBox > div {
display: grid; /* 帖子子元素也采用 grid 布局以方便约束它们自己的子元素 */
position: relative;
}
/* lrc歌词容器 :合并九宫格的第一行三个单元 */
.lrc_area {
grid-row-start: 1; /* 行的开始网格线 */
grid-row-end: 2; /* 行的结束网格线 */
grid-column-start: 1; /* 列的开始网格线 */
grid-column-end: 4; /* 列的结束网格线 */
place-items: center; /* 令子元素绝对居中 */
}
/* 修饰图容器 :合并九宫格的第二行第一个单元格和第三行第一个单元格 */
.pic_area {
grid-row-start: 2;
grid-row-end: 3;
grid-column-start: 2;
grid-column-end: 3;
place-items: center; /* 居中 */
}
/* 播放器区域 :合并九宫格第三行后两个单元格 */
.play_area {
grid-row-start: 3;
grid-row-end: 4;
grid-column-start: 2;
grid-column-end: 4;
place-items: center; /* 其下子元素绝对居中 */
cursor: pointer;
}
/* 播放器区域鼠标滑过时进度条和按钮动画 :上下移动 */
.play_area:hover #btnwrap, .play_area:hover #prog {
transform: translateY(var(--yy));
}
/* 播放器区域鼠标滑过时按钮动画 :形状和透明度 */
.play_area:hover #btnwrap {
background: linear-gradient(to top right, black, orange);
border-radius: 50%;
opacity: 1;
}
/* 按钮容器和进度条统一样式 */
#btnwrap, #prog {
position: absolute;
display: grid; /* 它们也用grid布局 */
place-items: center; /* 其内元素绝对居中 */
transition: .5s;
}
/* 按钮容器自己的样式 */
#btnwrap {
--yy: -15px;
width: 40px;
height: 40px;
left: 490px;
transform: rotate(45deg);
border-radius: 6px;
opacity: 0;
}
/* 播放按钮样式 */
#btnplay {
width: 20px;
height: 20px;
transform: translateX(3px);
background: #eee;
clip-path: polygon(0 0, 0% 100%, 100% 50%);
}
/* 暂停按钮样式 */
#btnpause {
width: 2px;
height: 20px;
border-style: solid;
border-width: 0px 4px;
border-color: transparent #eee;
display: none;
}
/* 进度条样式 */
#prog {
--yy: 20px;
width: 200px;
height: 16px;
left: 414px;
border-radius: 10px;
background: linear-gradient(90deg, hsla(160,100%,50%,.45), hsla(160,0%,0%,.5) 100%, transparent 0);
border: 1px solid gray;
font: normal 14px / 16px sans-serif;
color: snow;
text-shadow: 1px 1px 0 #111;
}
/* lrc歌词元素的样式 */
#lrc {
position: absolute;
top: 100;
font: bold 2.6em sans-serif;
color: hsla(160,100%,100%,.95);
text-shadow: 1px 1px 1px #000;
--motion: cover2;
--tt: 1s;
--state: running;
}
/* lrc歌词伪元素样式 */
#lrc::before {
position: absolute;
content: attr(data-lrc);
width: 0;
height: 100%;
left: 0;
top: 0;
color: hsla(160,80%,50%,.95);
overflow: hidden;
white-space: nowrap;
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>
<!-- 帖子html 代码 -->
<div class="mainBox">
<div class="lrc_area"><span id="lrc" data-lrc="花潮论坛lrc在线">花潮论坛lrc在线</span></div>
<div class="pic_area"><img src="https://wj.zp68.com/lxx/yunhua/2022/10/17/yw.gif" alt="" style="width: 304px; height: 458px;" /></div>
<div class="play_area">
<div id="btnwrap"><span id="btnplay"></span><span id="btnpause"></span></div>
<div id="prog">00:00 | 00:00</div>
</div>
</div>
<!-- 帖子html代码结束 -->
<!-- 下面是帖子的 JS 代码 : 用于实现播放器控制和lrc歌词同步 -->
<script>
let mKey = 0, mFlag = true, aud = new Audio();
let lrcAr = [
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
];
aud.src = 'https://wj.zp68.com/lxx/yunhua/2022/10/17/ssdxs.mp3';
aud.autoplay = true;
aud.loop = true;
btnwrap.onclick = () => aud.paused ? aud.play() : aud.pause();
prog.onclick = (e) => 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.background= 'linear-gradient(90deg, hsla(160,100%,50%,.45), hsla(160,0%,0%,.5) ' + aud.currentTime / aud.duration * 100 + '%, hsla(160,0%,100%,.35) 0)';prog.innerText = toMin(aud.currentTime) + ' | ' + 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;};
</script>
<br><br><br><br><br><br><br><br><br><br><br><br><br>
@马黑黑
黑黑套用一个{:4_173:} 学习黑黑这个网格布局制作还是需要先认真学习一下黑黑的教程的,今天我直接套用做一个 今天因为是动图效果就加了中间的一个效果,中间修饰图容器我修改了一下加了个动图,发现居中效果还可以就这样了。 播放器和歌词按黑黑的布局制作的,就中间的动图是自己加在修饰图容器里 小辣椒套用了岁月和黑黑老师的精华,好漂亮啊{:4_187:} 做此类贴小辣椒是高手了,棒棒哒{:4_187:}{:4_185:} 千羽 发表于 2022-10-17 21:08
小辣椒套用了岁月和黑黑老师的精华,好漂亮啊
哈哈~~~把最美的送给大家 千羽 发表于 2022-10-17 21:09
做此类贴小辣椒是高手了,棒棒哒
这个网络布局制作也是第一次,千羽学习做一次 小辣椒 发表于 2022-10-17 21:17
这个网络布局制作也是第一次,千羽学习做一次
小辣椒,俺哪会啊,不敢做{:4_203:} 千羽 发表于 2022-10-17 21:22
小辣椒,俺哪会啊,不敢做
去看看黑黑的教程板块,我就是一面看一面做的 亲爱的制作里的动态元素总是很惊艳,里面还有岁月的粒子效果呢,很棒{:4_199:} 漂亮漂亮 这个有自己的添加,也是有自己思考的,不算完全套用{:4_187:} 小辣椒 发表于 2022-10-17 20:56
@马黑黑
黑黑套用一个
这是代码重用,已经不是一般意义上的套用了 红影 发表于 2022-10-17 21:53
这个有自己的添加,也是有自己思考的,不算完全套用
对,我再15楼上也这么说 我也要傻的很帅 好震撼的音乐,小辣椒朋友真棒! 欣赏精美音画佳作!