- 資訊首頁(yè) > 開(kāi)發(fā)技術(shù) > web開(kāi)發(fā) > JavaScript >
- js實(shí)現網(wǎng)頁(yè)音樂(lè )播放器
本文為大家分享了簡(jiǎn)單的html,音樂(lè )播放器制作代碼,供大家參考,具體內容如下
首先第一步找圖片資源 音樂(lè )資源 放入到img文件夾中
第二步對頁(yè)面布局進(jìn)行布置
第三步書(shū)寫(xiě)js代碼
復制代碼運行的時(shí)候需要將圖片資源,音樂(lè )資源換個(gè)名稱(chēng)。
運行實(shí)現圖片的切換,效果如圖:
代碼如下:
希望各位喜歡?。?!
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <style type="text/css"> * { margin: 0; padding: 0; } body{ background-color:#596653; } .yinyue { width: 300px; height: 300px; border: 1px solid aqua; margin:50px 500px; } .bofang { width: 100px; height: 100px; background-color: aqua; } .muted ,.play,.prefer,.next{ width: 60px; height: 30px; background-color: aquamarine; text-align: center; line-height: 30px; } #kongzhi ,#shangxia { margin: 10px 530px; } </style> </head> <body> <div id="content"> <img class="yinyue" src="img/yinyue1.jpg" > <audio src="img/yinyue1.mp3" > </audio> <div id="anniu"> <div id="kongzhi"> <button class="muted" type="button" >靜音</button> <img class="bofang" src="img/播放.png" > <button class="play" type="button" >播放</button> </div> <div id="shangxia"> <button class="prefer" type="button">上一首</button> <span>音量</span> <input class="volume" type="range" min="0" max="1"step="0.01" /> <button class="next" type="button">下一首</button> </div> </div> </div> <script type="text/javascript"> var index=0; var srcs=['img/yinyue1.mp3','img/yinyue2.mp3','img/yinyue3.mp3']; var imgArr=['img/yinyue1.jpg','img/yinyue2.jpg','img/yinyue3.jpg']; var audio =document.querySelector("audio"); var playBtn =document.querySelector(".play"); var mutedBtn =document.querySelector(".muted"); var volumnBtn=document.querySelector(".volume"); var bofang= document.querySelector('.bofang'); var prefer =document.querySelector(".prefer"); var nextBtn=document.querySelector(".next"); var yinyue =document.querySelector(".yinyue") playBtn.onclick=function(){ if(audio.paused===true){ audio.play(); bofang.src='img/播放.png'; audio.value="播放"; }else{ audio.pause(); bofang.src ='img/暫停.png'; audio.value="暫停"; } } mutedBtn.onclick=function(){ if(audio.muted==true){ audio.muted=false; } else{ audio.muted=true; bofang.src ='img/靜音.png'; } } volumnBtn.onchange=function(){ audio.volume=volumnBtn.value; } prefer.onclick=function(){ index--; if(index<0){ index=srcs.length-1; } audio.srcs=srcs[index]; yinyue.src=imgArr[index]; } nextBtn.onclick=function(){ index++; if(index==srcs.length){ index=0; } audio.src=srcs[index]; yinyue.src=imgArr[index]; } </script> </body> </html>
以上就是本文的全部?jì)热?,希望對大家的學(xué)習有所幫助,也希望大家多多支持腳本之家。
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站