html5 video button that takes video to specific time

前端 未结 2 505
名媛妹妹
名媛妹妹 2020-12-30 06:47

I\'m trying to place a video that autoplays without controls but I want to add three custom buttons below the video, each button jumps the video to a specific time. Not usin

2条回答
  •  旧时难觅i
    2020-12-30 07:14

    You can set the currentTime attribute of a video. Using your example:

    var vidLinks = document.querySelectorAll('.navBtns a');
    
    for(var i = 0, l = vidLinks.length; ++i){
        makeVideoLink(vidLinks[i]);
    }
    
    function jumpToTime(time){
        v.currentTime = time;
    }
    
    function makeVideoLink(element){
        // Extract the `t=` hash from the link
        var timestamp = element.hash.match(/\d+$/,'')[0] * 1000;
    
        element.addEventListener('click', function videoLinkClick(e){
            jumpToTime(timestamp);
    
            return false;
        },false)
    }
    

    Mozilla's Developer Network site has a great list of HTML5 media element properties.

提交回复
热议问题