|
|

楼主 |
发表于 2022-10-12 07:48
|
显示全部楼层
本帖最后由 马黑黑 于 2022-10-12 07:50 编辑
播放控制器使用单标签实现,但CSS代码比较多:
/* 按钮 */
.btnplay {
position: absolute;
top: 0px;
left: 100px;
width: 80px;
height: 80px;
border-radius: 50%;
box-shadow: 15px 10px 0 0 orange;
cursor: pointer;
z-index: 10;
animation: swing 1s linear infinite alternate;
}
/* 伪元素一:用以调整鼠标点击的接收区域 */
.btnplay::before {
position: absolute;
content: '';
left: 20px;
top: 12px;
width: 100%;
height: 100%;
}
/* 伪元素二:模拟伴星 */
.btnplay::after {
position: absolute;
content: '';
left: 25px;
top: 25px;
width: 40%;
height: 40%;
border-radius: 50%;
background: tan;
box-shadow: 0 0 30px 0px purple, 0 0 100px 0 snow;
}
/* 关键帧动画:摇摆 */
@keyframes swing {
from { transform: rotate(0deg); }
to { transform: rotate(30deg); }
}
HTML就一个标签代码:
<span class="btnplay" title="播放/暂停"></span>
JS中,播放器状态控制函数里,设置一下动画的暂停与继续:
let mState = () => aud.paused ? (btnplay.style.animationPlayState = 'paused', lrc.style.setProperty('--state', 'paused')) : (btnplay.style.animationPlayState = 'running', lrc.style.setProperty('--state', 'running'));
这个函数的运行,有诸多触发节点,比如按钮的点击、歌曲能不能自动播放、歌曲是播放中还是暂停中等等,都通过对播放器的监测实现,这里不多做解释。监控代码在这两行:
aud.addEventListener('pause', () => mState());
aud.addEventListener('play', () => mState());
|
评分
-
| 参与人数 1 | 威望 +50 |
金钱 +100 |
经验 +50 |
收起
理由
|
红影
| + 50 |
+ 100 |
+ 50 |
赞一个! |
查看全部评分
|