html5 video button that takes video to specific time

前端 未结 2 504
名媛妹妹
名媛妹妹 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条回答
  •  一生所求
    2020-12-30 07:28

    Your links feature two different problems:

    1. they have the target="_blank" attribute, therefor they open a new window/tab. (get rid of those)
    2. you're linking to the video itself, not to the page with the video embedded. This just won't work as expected.

    To control a video on a page directly without leaving the page, you'll need some javascript. Here you'll find an example how this will work.

    JS Fiddle: Video CurrentTime Example

    You'll need a function to jump to the specific time on click of one of your links, that would be (for instance):

    var firstlink = document.getElementByTagName('a')[0];
    firstlink.addEventListener("click", function (event) {
        event.preventDefault();
        myvideo.currentTime = 7;
        myvideo.play();
    }, false);
    

提交回复
热议问题