How to pause a HTML5 video on an event?

懵懂的女人 提交于 2019-11-26 16:28:09

问题


I am building a website with HTML5-<video> in fullscreen background. There are pages in shape of <div>s becoming visible with SWF-container player in them that cause serious CPU performance issues when both media play. So I want to add a simple javascript command that pauses the background video when a project-<div> becomes visible. Would be nice if it resumes again the playback when it gets closed/hidden.

Thanks in advance.


回答1:


document.getElementById('myvideotag').pause();

Note that there is no stop() method. In the function that shows/hides your DIV, place the play/pause function there.

More resources here: http://www.digitaria.com/blogs/html5-video-skinning-tutorial-part-2-play-buttons




回答2:


My personal favourite is a small onclick handler added to html attribute, like this:

<video onclick="this.paused? this.play() : this.pause()">



回答3:


since there are not traditional events on div hide/show you have to play() and pause() your video element when you call the functions that make your div appear/disappear



来源:https://stackoverflow.com/questions/4155329/how-to-pause-a-html5-video-on-an-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!