<audio id="play1"> <source src="auto/旅行.mp3"></source> </audio> <audio id="play2"> <source src="auto/薛明媛,朱贺 - 非酋.mp3"></source> </audio> <audio id="play3"> <source src="auto/杨宗纬 - 越过山丘.mp3"></source> </audio>
play1=document.getElementById("play1");
play2=document.getElementById("play2");
play3=document.getElementById("play3");
play=[play1,play2,play3];
//点击播放、暂停
function start(){
minute=0;
if(flag){
imagePause();
play[index].pause();
}else{
rotate();
play[index].play();
reducejindutiao();
addtime();
jindutiao();
for (var i=0;i<play.length;i++) {
audioall[i].style.color="white";
}
audioall[index].style.color="red";
}
}
//图片旋转,每30毫米旋转5度
function rotate(){
var deg=0;
flag=1;
timer=setInterval(function(){
image.style.transform="rotate("+deg+"deg)";
deg+=5;
if(deg>360){
deg=0;
}
},30);
}
function imagePause(){
clearInterval(timer);
flag=0;
}
function jindutiao(){
//获取当前歌曲的歌长
var lenth=play[index].duration;
timer1=setInterval(function(){
cur=play[index].currentTime;//获取当前的播放时间
fillbar.style.width=""+parseFloat(cur/lenth)*300+"px";
},50)
}
//播放时间
function addtime(){
timer2=setInterval(function(){
cur=parseInt(play[index].currentTime);//秒数
var temp=cur;
minute=parseInt(temp/60);
if(cur%60<10){
time.innerHTML=""+minute+":0"+cur%60+"";
}else{
time.innerHTML=""+minute+":"+cur%60+"";
}
},1000);
}
//上一曲
function reduce(){
qingkong();
reducejindutiao();
pauseall();
index--;
if(index==-1){
index=play.length-1;
}
start();
}
//下一曲
function add(){
qingkong();
reducejindutiao();
pauseall();
index++;
if(index>play.length-1){
index=0;
}
start();
}
//点击文字切歌
function change(e){
var musicName=e.target;
//先清空所有的
for (var i=0;i<audioall.length;i++) {
audioall[i].style.color="white";
if(audioall[i]==musicName){
musicName.style.color="red";
qingkong();
reducejindutiao();
pauseall();
index=i;
start();
}
}
}
//将进度条置0
function reducejindutiao(){
clearInterval(timer1);
fillbar.style.width="0";
}
//音乐停止
function pauseall(){
for (var i=0;i<play.length;i++) {
if(play[i]){
play[i].pause();
}
}
}
function qingkong(){//清空所有的计时器
imagePause();
clearInterval(timer2);
}
//调整播放进度
function adjust(e){
var bar=e.target;
var x=e.offsetX;
var lenth=play[index].duration;
fillbar.style.width=x+"px";
play[index].currentTime=""+parseInt(x*lenth/300)+"";
play[index].play();
}
//调整音量大小
function changeVolume(e){
var x=e.offsetX+20;
play[index].volume=parseFloat(x/200)*1;
//改变按钮的位置
volume3.style.left=""+x+"px";
}
//随机播放歌曲
function suiji(e){
var img=e.target;
img2.style.border="";
img.style.border="1px solid red";
}
//顺序播放
function shunxu(e){
var img=e.target;
img1.style.border="";
img.style.border="1px solid red";
clearInterval(suijiplay);
shunxuplay=setInterval(function(){
if(play[index].ended){
add();
}
},1000);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有