jq实现音乐暂停播放
案列
总体思路
-
完成html与css和动画
-
实现播放暂停主要代码
-
最后在暂停和播放的时候添加一些css动画属性
js
-
-
$('.open').click(function(){//点击次执行函数
-
audios()
-
})
-
function audios(){
-
console.log($('#aud'))
-
var play=$('#aud')[0]//将音乐转换成数组
-
console.log(play)
-
if(play.paused){//如果音乐已经暂停了
-
play.play()//就播放
-
$('.open span').text('播放')
-
$('.music-img').css('animation','fu2 5s ease infinite')
-
$('.music-m').after().css('animation','fu1 2s infinite')
-
}else{
-
play.pause()//暂停
-
$('.open span').text('暂停')
-
$('.music-img').css('animation-play-state','paused')
-
$('.music-m').after().css('animation-play-state','paused')//动画暂停
-
}
-
}
css
-
-
body{
-
display: flex;
-
justify-content: center;
-
align-items: center;
-
height: 100vh;
-
flex-direction: column;
-
background: #333;
-
}
-
.music{
-
position: relative;
-
display: flex;
-
justify-content: center;
-
align-items: center;
-
-
}
-
h2{
-
color: #fff;
-
}
-
.music-img{
-
position: relative;
-
width: 300px;
-
height: 300px;
-
border-radius: 50%;
-
overflow: hidden;
-
margin: 8rem 0;
-
/* animation: fu2 5s ease infinite;*/
-
}
-
.music-img::before{
-
content: '';
-
display: inline-block;
-
position: absolute;
-
z-index: 10;
-
top: 41%;
-
left: 39%;
-
height: 60px;
-
width: 60px;
-
background: #999;
-
border-radius: 50%;
-
}
-
.music-img::after{
-
content: '';
-
display: inline-block;
-
position: absolute;
-
top: 35%;
-
left: 32%;
-
height: 100px;
-
width: 100px;
-
background: #333;
-
border-radius: 50%;
-
}
-
-
img{
-
width: 100%;
-
height: 100%;
-
}
-
.music-m{
-
position: absolute;
-
width: 350px;
-
height: 350px;
-
background: #161616;
-
border-radius: 50%;
-
transition: all 1s;
-
}
-
@keyframes fu1{
-
0%{
-
filter: hue-rotate(0deg);
-
}
-
50%{
-
filter: hue-rotate(180deg);
-
}
-
100%{
-
filter: hue-rotate(360deg);
-
}
-
}
-
@keyframes fu2{
-
0%{
-
transform: rotate(0deg);
-
}
-
-
100%{
-
transform: rotate(360deg);
-
}
-
}
-
.music-m::before{
-
position: absolute;
-
top: -1.5rem;
-
content: '';
-
display: inline-block;
-
left: -1.8rem;
-
width: 400px;
-
height: 400px;
-
border: 4px solid #FF005F;
-
border-radius: 50%;
-
animation: fu1 2s infinite;
-
}
-
.music-bar{
-
width: 500px;
-
height: 50px;
-
background: #ccc;
-
color: #FF005F;
-
display: flex;
-
justify-content: center;
-
align-items: center;
-
cursor: pointer;
-
}
-
.music-bar span{
-
border:2px solid #FF005F;
-
display: inline-block;
-
padding: .5rem 1rem;
-
background: #efefef;
-
}
-
audio{
-
display: none;
-
}
html
-
<h2>not shy</h2>
-
<div class="music">
-
<div class="music-m"></div>
-
<div class="music-img"><img src="img/not_shy.png" alt="not_shy" role="img"></div>
-
</div>
-
<div class="music-bar">
-
<div class="open"><span>播放</span></div>
-
</div>
-
<audio id="aud" src="shucai/not_shy.mp3" controls></audio>
-
<script src="http://code.jquery.com/jquery-1.12.4.min.js"></script>//引入jq
如果文章有误欢迎评论区留言QAQ
-
-
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhigeege
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
excel下划线不显示怎么办
PHP中文网 06-23 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel图片置于文字下方的方法
PHP中文网 06-27 -
微信运动停用后别人还能看到步数吗
PHP中文网 07-22