Custom progress bar for <audio> and HTML5 elements

前端 未结 3 1255
-上瘾入骨i
-上瘾入骨i 2021-01-30 23:45

I am mind boggled at working out how to create a custom seekbar for an audio player using the tag and simple Javascript.

Current Code:

    

        
3条回答
  •  广开言路
    2021-01-31 00:07

    If you want smooth progress bar,try somethink like that

    HTML:

    CSS:

    .hp_slide{
        width:100%;
        background:white;
        height:25px;
    }
    .hp_range{
        width:0;
        background:black;
        height:25px;
    }
    

    JS:

    var player = document.getElementById('player');    
    player.addEventListener("timeupdate", function() {
        var currentTime = player.currentTime;
        var duration = player.duration;
        $('.hp_range').stop(true,true).animate({'width':(currentTime +.25)/duration*100+'%'},250,'linear');
    });
    

    Pretty rough,but works

提交回复
热议问题