本文转自:金羊网00:0000:00详情收起00:0000:00// 音频播放var a...|为“数字白云”建设保驾护航!广州白云区数据安全监测与运行中心揭牌
本文转自:金羊网00:0000:00详情收起00:0000:00//音频播放varaudioPlayer=document.querySelector('.audio-box');//varplayPause=audioPlayer.querySelector('#playPause');varplaypauseBtn=audioPlayer.querySelector('.audio-bottom-control-play');varplaypauseBtnSmall=audioPlayer.querySelector('.audio-left');//varloading=audioPlayer.querySelector('.loading');varprogress=audioPlayer.querySelector('.progress');varprogressSmall=audioPlayer.querySelector('.progresssmall');varsliders=audioPlayer.querySelectorAll('.slider');varvolumeBtn=audioPlayer.querySelector('.volume-btn');varvolumeControls=audioPlayer.querySelector('.volume-controls');varvolumeProgress=volumeControls.querySelector('.slider.progress');varplayer=audioPlayer.querySelector('#audio-resource');varcurrentTime=audioPlayer.querySelector('.audio-bottom-time-now');varcurrentTimeSmall=audioPlayer.querySelector('.audio-time-now');vartotalTime=audioPlayer.querySelector('.audio-bottom-time-all');vartotalTimeSmall=audioPlayer.querySelector('.audio-time-all');varrefreshbtn=audioPlayer.querySelector('.audio-bottom-control-refresh');//varspeaker=audioPlayer.querySelector('#speaker');vardraggableClasses=['pin'];varcurrentlyDragged=null;window.addEventListener('mousedown',function(event){if(!isDraggable(event.target))returnfalse;currentlyDragged=event.target;varhandleMethod=currentlyDragged.dataset.method;this.addEventListener('mousemove',window[handleMethod],false);window.addEventListener('mouseup',function(){currentlyDragged=false;window.removeEventListener('mousemove',window[handleMethod],false);},false);});playpauseBtn.addEventListener('click',togglePlay);playpauseBtnSmall.addEventListener('click',togglePlay);player.addEventListener('timeupdate',updateProgress);refreshbtn.addEventListener('click',refreshAll);player.addEventListener('volumechange',updateVolume);player.addEventListener('loadedmetadata',function(){totalTime.textContent=formatTime(player.duration);totalTimeSmall.textContent=formatTime(player.duration);});player.addEventListener('canplay',makePlay);player.addEventListener('ended',function(){//playPause.attributes.d.value="";//player.currentTime=0;$('.audio-left,.audio-yuan').addClass('pause');$('.audio-left,.audio-yuan').removeClass('play');$('.audio-pointer').addClass('stopplaydeg');$('.audio-pointer').removeClass('playdeg');$('.audio-bottom-control-play').removeClass('audio-bottom-control-ing');$('.audio-bottom-control-play').addClass('audio-bottom-control-stop');});volumeBtn.addEventListener('click',function(){volumeBtn.classList.toggle('open');volumeControls.classList.toggle('hidden');});//window.addEventListener('resize',directionAware);sliders.forEach(function(slider){varpin=slider.querySelector('.pin');slider.addEventListener('click',window[pin.dataset.method]);});//directionAware();functionisDraggable(el){varcanDrag=false;varclasses=Array.from(el.classList);draggableClasses.forEach(function(draggable){if(classes.indexOf(draggable)!==-1)canDrag=true;});returncanDrag;}functioninRange(event){varrangeBox=getRangeBox(event);varrect=rangeBox.getBoundingClientRect();vardirection=rangeBox.dataset.direction;if(direction=='horizontal'){varmin=rangeBox.offsetLeft;varmax=min+rangeBox.offsetWidth;if(event.clientX<min||event.clientX>max)returnfalse;}else{varmin=rect.top;varmax=min+rangeBox.offsetHeight;if(event.clientY<min||event.clientY>max)returnfalse;}returntrue;}functionupdateProgress(){varcurrent=player.currentTime;varpercent=current/player.duration*100;progress.style.width=percent+'%';progressSmall.style.width=percent+'%';currentTime.textContent=formatTime(current);currentTimeSmall.textContent=formatTime(current);}functionupdateVolume(){volumeProgress.style.height=player.volume*100+'%';if(player.volume>=0.5){//speaker.attributes.d.value='';}elseif(player.volume<0.5&&player.volume>0.05){//speaker.attributes.d.value='';}elseif(player.volume<=0.05){//speaker.attributes.d.value='';}}functiongetRangeBox(event){varrangeBox=event.target;varel=currentlyDragged;if(event.type=='click'&&isDraggable(event.target)){rangeBox=event.target.parentElement.parentElement;}if(event.type=='mousemove'){rangeBox=el.parentElement.parentElement;}returnrangeBox;}functiongetCoefficient(event){varslider=getRangeBox(event);varrect=slider.getBoundingClientRect();varK=0;if(slider.dataset.direction=='horizontal'){varoffsetX=event.clientX-slider.offsetLeft;varwidth=slider.clientWidth;K=offsetX/width;}elseif(slider.dataset.direction=='vertical'){varheight=slider.clientHeight;varoffsetY=event.clientY-rect.top;K=1-offsetY/height;}returnK;}functionrewind(event){if(inRange(event)){player.currentTime=player.duration*getCoefficient(event);}}functionchangeVolume(event){if(inRange(event)){player.volume=getCoefficient(event);}}functionformatTime(time){varmin=Math.floor(time/60);varsec=Math.floor(time%60);return(min<10?'0'+min:min)+':'+(sec<10?'0'+sec:sec);}functiontogglePlay(){if(player.paused){//playPause.attributes.d.value="";$('.audio-left,.audio-yuan').addClass('play');$('.audio-left,.audio-yuan').removeClass('pause');$('.audio-pointer').addClass('playdeg');$('.audio-pointer').removeClass('stopplaydeg');$('.audio-bottom-control-play').removeClass('audio-bottom-control-stop');$('.audio-bottom-control-play').addClass('audio-bottom-control-ing');player.play();}else{//playPause.attributes.d.value="";$('.audio-left,.audio-yuan').addClass('pause');$('.audio-left,.audio-yuan').removeClass('play');$('.audio-pointer').addClass('stopplaydeg');$('.audio-pointer').removeClass('playdeg');$('.audio-bottom-control-play').removeClass('audio-bottom-control-ing');$('.audio-bottom-control-play').addClass('audio-bottom-control-stop');player.pause();}}functionmakePlay(){//playpauseBtn.style.display='block';//playpauseBtnSmall.style.display='block';//loading.style.display='none';}//functiondirectionAware(){//if(window.innerHeight<250){//volumeControls.style.bottom='-54px';//volumeControls.style.left='54px';//}elseif(audioPlayer.offsetTop<154){//volumeControls.style.bottom='-164px';//volumeControls.style.left='-3px';//}else{//volumeControls.style.bottom='52px';//volumeControls.style.left='-3px';//}//}functionrefreshAll(){player.currentTime=0;progress.style.width=0;progressSmall.style.width=0;currentTime.textContent='00:00';currentTimeSmall.textContent='00:00';}
文/羊城晚报全媒体采访人员符畅
- 本文转自:中国经济网8月19日|共建AIoT生态,旷视2022企业业务合作伙伴大会北京站首站圆满成功
- 本文转自:中国经济网8月18日|共拓到家服务生态 苏宁易购帮客与雨虹到家签署战略合作
- 本文转自:新华网8月19日|新华社国家重点实验室与中仪英斯泰克、北京大数据研究院签署三方战略合作协议
- 本文转自:北青网我在服贸会等你能模拟各地冰雪条件的智能实验室|最大规模体育专题展将亮相服贸会
- 本文转自:北京日报北京日报客户端 | 记者 白波 通讯员 李四航 杜晓丰 马超洋8月18...|华为海关和港口军团设创新实验室,瞄准全球供应链重要一环
- 本文转自:新闻晨报好消息!杨浦区中心医院中国医师节义诊活动来了!一起来看看吧左右滑动查看...|好消息!杨浦区中心医院中国医师节义诊活动来了
- 本文转自:中国警察网公安部“互联网+政务服务”平台2.|【公安部新闻发布会】公安部“互联网+政务服务”平台2.0出现三大新变化
- 本文转自:北京日报北京日报客户端 | 记者 孙颖 通讯员 王东坡用4秒钟弹射到40米高空...|模拟火星重力!北京在建航天领域的“跳楼机”
- 图解·文山这十年 | 商务平台逐步夯实 贸易经济日趋活跃
- 本文转自:新华网8月17日|与用户共创共享共成长 岚图梦想俱乐部成立