简体   繁体   中英

make html5 video go to first frame when it ends?

I have a simple video html5 tag, bound to an "ended" event:

$('#video').show().trigger("play").bind('ended', function () { 
//code
}

Since I'm "showing" and "hiding" this through a button click, I wanted to make it return to the first frame on that last function, so it would start from the beginning the next time it appears (right now it starts from the ending, and it causes a nasty flicker when it goes from the last to the first frame).

Is that possible with jQuery?

Thanks in advance!

You can use something like

$('#video').show().trigger("play").bind('ended', function () { 
    this.currentTime = 0;
}

You can only set the currentTime if the loadedmetadata event has passed.

This goes in the head:

<script>
function Reset() { document.getElementById('MyVideo').load(); }
</script>

This goes in the video tag:

<video ID="MyVideo" onended="Reset()" [plus your other parameters] >

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM