欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js實(shí)現(xiàn)音頻控制進(jìn)度條功能

 更新時(shí)間:2017年04月01日 10:08:03   作者:donyFeng6  
本文主要介紹了js實(shí)現(xiàn)音頻控制進(jìn)度條功能的示例代碼。具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧

效果圖:

代碼如下:

<!doctype html>
<html>
<head>
<meta name="author" content="dony">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="pragma" content="no-cache">
<meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>音頻控制進(jìn)度條</title>
<style type="text/css">

body,div{padding: 0;margin: 0;}
.m-main{width:560px; height: 100%; margin: 3% auto; background-color:#30a5ff;}
.m-main video{display: none; }
.m-main .player {
  width: 100%;
  height: 150px;
  position: relative;
  bottom: 0px;
}
.m-main .player>a{display: inline-block; width: 20%; margin: 0 auto; padding: 5%; color: #FFF; text-align: center;}
.m-main .play-box {
  width: 100%;
  margin: 0 auto;
}

.m-main .play-box .left {
  width: 100%;
  float: left;
}

.m-main .play-box .left p.timeline { width: 70%;height: 10px; background-color: rgba(216, 216, 216, 0.5); border-radius: 5px; margin:30px auto 0; position: relative; z-index: 2; }
.m-main .play-box .left p.timeline span {position: relative; width: 0px; height: 10px; background-color: #FFF; border-radius: 5px; display: block; -webkit-transition: width ease-out 0.3s;-o-transition: width ease-out 0.3s;transition: width ease-out 0.3s;}
.m-main .play-box .left p.timeline span:after{content: ""; position: absolute; top: -4px; right:-0.6rem;width: 1.2rem; height:1.2rem; border-radius: 50%;background-color: #FFF;}
.m-main .play-box .left div.info { height: 26px; line-height: 26px; font-size: 14px; color: #000; position: relative; top: -18px; margin:0 10px; z-index: 1;color: #FFF;}
.m-main .play-box .left div.info .size { float: left; display: block;}
.m-main .play-box .left div.info .timeshow { float: right; display: block;}
</style>
</head>
<body>
<div class="m-main">
  <div class="player">
   <a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" id="js-play">播放</a>
   <a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" id="js-pause">暫停</a>
    <div class="play-box">
      <div class="left">
        <p class="timeline"><span style=""></span></p>
        <div class="info">
          <span class="size">00:00</span>
          <span class="timeshow">00:00</span>
        </div>
      </div>
    </div>
  </div>
 <div class="video">
 <video controls autoplay name="media" id="js-video"><source src="http://chipsguide.snaillove.com/Public/Uploads/file_server_storage/Audio/2017/03/23/19/192_20003137.mp3" type="video/mp4"></video>
 </div>
</div>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
  $(function(){
   AudioControl('js-video')
   function AudioControl(id){
     // 音頻控制進(jìn)度條
     var audio = document.getElementById(id);
     $(audio).on('loadedmetadata',function(){
    audio.pause();
    // 進(jìn)度條控制
     $(document).on('touchend','.timeline',function(e){
       var x = e.originalEvent.changedTouches[0].clientX-this.offsetLeft;
       var X = x < 0 ? 0 : x ;
       var W = $(this).width();
       var place = X > W ? W : X;
       audio.currentTime = (place/W).toFixed(2)*audio.duration
       $(this).children().css({width:(place/W).toFixed(2)*100+"%"})
     });
     // 播放
    $(document).on('click','#js-play',function(){
    audio.play()
    });
    // 暫停
    $(document).on('click','#js-pause',function(){
    audio.pause()
    });
     })
     setInterval(function () {
       var currentTime = audio.currentTime;
       setTimeShow(currentTime);
     }, 1000);
     // 設(shè)置播放時(shí)間
   function setTimeShow(t) {
     t = Math.floor(t);
     var playTime = secondToMin(audio.currentTime);
     $(".size").html(playTime);
     $('.timeshow').text(secondToMin(audio.duration))
     $('.timeline').children().css({width:(t/audio.duration).toFixed(4)*100+"%"})
   }
     // 計(jì)算時(shí)間
   function secondToMin(s) {
     var MM = Math.floor(s / 60);
     var SS = s % 60;
     if (MM < 10)
       MM = "0" + MM;
     if (SS < 10)
       SS = "0" + SS;
     var min = MM + ":" + SS;
     return min.split('.')[0];
   }
   }
  })
</script>
</body>
</html>

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

  • webpack 從指定入口文件中提取公共文件的方法

    webpack 從指定入口文件中提取公共文件的方法

    這篇文章主要介紹了webpack 從指定入口文件中提取公共文件的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-11-11
  • 捕獲關(guān)閉窗口的腳本

    捕獲關(guān)閉窗口的腳本

    對(duì)于需要獲取一個(gè)窗口關(guān)閉后的返回信息時(shí),需要用的到。
    2009-01-01
  • js實(shí)現(xiàn)簡(jiǎn)單放大鏡特效

    js實(shí)現(xiàn)簡(jiǎn)單放大鏡特效

    這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)簡(jiǎn)單放大鏡特效,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-03-03
  • Javascript?、Vue禁止鼠標(biāo)右鍵點(diǎn)擊事件實(shí)例

    Javascript?、Vue禁止鼠標(biāo)右鍵點(diǎn)擊事件實(shí)例

    這篇文章主要給大家介紹了關(guān)于Javascript?、Vue禁止鼠標(biāo)右鍵點(diǎn)擊事件的相關(guān)資料,禁止右鍵的原理是通過(guò)JavaScript阻止瀏覽器右鍵事件的默認(rèn)行為,從而達(dá)到禁止右鍵的效果,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-11-11
  • 小程序?qū)崿F(xiàn)自定義導(dǎo)航欄適配完美版

    小程序?qū)崿F(xiàn)自定義導(dǎo)航欄適配完美版

    這篇文章主要介紹了小程序?qū)崿F(xiàn)自定義導(dǎo)航欄適配完美版,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • HTML頁(yè)面如何象ASP一樣接受參數(shù)

    HTML頁(yè)面如何象ASP一樣接受參數(shù)

    HTML頁(yè)面如何象ASP一樣接受參數(shù)...
    2007-02-02
  • escape編碼與unescape解碼漢字出現(xiàn)亂碼的解決方法

    escape編碼與unescape解碼漢字出現(xiàn)亂碼的解決方法

    這篇文章主要介紹了escape編碼與unescape解碼漢字出現(xiàn)亂碼的解決方法,需要的朋友可以參考下
    2014-07-07
  • Bootstrap面板學(xué)習(xí)使用

    Bootstrap面板學(xué)習(xí)使用

    這篇文章主要為大家詳細(xì)介紹了Bootstrap面板的學(xué)習(xí)使用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • JavaScript判斷前綴、后綴是否是空格的方法

    JavaScript判斷前綴、后綴是否是空格的方法

    這篇文章主要介紹了JavaScript判斷前綴、后綴是否是空格的方法,涉及javascript操作字符串的正則替換、判斷與屬性操作技巧,需要的朋友可以參考下
    2015-04-04
  • 用javascript做拖動(dòng)布局的思路

    用javascript做拖動(dòng)布局的思路

    這幾天不是很忙,就找了些拖動(dòng)布局方面的資料看看,也學(xué)著寫(xiě)了個(gè)拖動(dòng)布局的效果,沒(méi)想到花了好多時(shí)間,七拼八湊,總算是把這個(gè)效果寫(xiě)出來(lái)了。
    2010-10-10

最新評(píng)論