简体   繁体   中英

HTML5 video JS onclick play/pause/play from beginning

I have a local video file to play using html5 and js. I'd like the user to click on the video image to play, then next click pause, but then third click would play again from the beginning. Am JS novice, but found this great code to be able to do inline except it restarts from the current pointer. Is there a way to use a similar statement to have the video restart from the beginning after pause without a load, etc. using similar conditional code? Have not seen exactly what I want without more extensive script...maybe that is necessary?

<video controlsList="nodownload nofullscreen" 
        onclick="this.paused ? this.play() : this.pause();">
        <source src="img/white_noise.mp4" type="video/mp4">
        Some failure message
</video>

我想通了...会离开的,以防它对其他人有帮助:

onclick="this.paused ? this.play() : (this.pause(),this.currentTime=0);"

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