HTML5 Video with Fancybox

杀马特。学长 韩版系。学妹 提交于 2019-12-10 09:52:13

问题


I am having an issue with getting HTML5 video to autoplay on load into Fancybox. I have an HTML5 video loaded into a div that is hidden and therefore can't have autoplay enabled in the tag. I then call it one an image click with a Fancybox inline and a ref to the div. Everything works as it should except I just want the video to play when then Fancybox opens it?? Any ideas would be appreciated.


回答1:


You can autoplay the video as soon as it is opened in fancybox. The problem with the inline video is that if you close it then it will pause and the next time you open it in fancybox, the video will be open in the same place/track it was when closed ... and it won't "auto-resume" (the action is autoplay on start).

Anyway, this option should do the trick:

'onComplete': function(){
$("#myVideo").find('video').attr('autoplay','autoplay');
}

#myVideo is the ID of the DIV, which contains the video tag.

Since you are using the inline method, it would worth to have a look at one existing bug and its workaround here.

Eventually, you may prefer to use the API option 'content' instead, to avoid the inline type issues:

'content': '<video autoplay="autoplay" preload="none" poster="path/image.jpg" width="640" height="360" controls="controls"><source autoplay="autoplay" src="path/video.ogg" type="video/ogg">your browser does not support the HTML 5 video tag</video>'


来源:https://stackoverflow.com/questions/8184677/html5-video-with-fancybox

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