HTML5 audio clicking the progress bar to move to a different time

前端 未结 4 1271
暗喜
暗喜 2021-01-18 03:43

    
    
               


        
4条回答
  •  天涯浪人
    2021-01-18 04:05

    Given some html that looks like this:

    In order to seek to a specific time in the video as a result of a click event the js would look like this:

    var player = document.querySelector("video");
    var progressBar = document.querySelector("progress");
    progressBar.addEventListener("click", seek);
    
    function seek(e) {
        var percent = e.offsetX / this.offsetWidth;
        player.currentTime = percent * player.duration;
        progressBar.value = percent / 100;
    }
    

    However, this doesn't address how to seek on a click/drag (like most video players do). include script

提交回复
热议问题