我试图让视频在视频结束时退出全屏,但它不会。我搜索并找到了方法来做到这一点,但我一生都无法让它发挥作用。我正在 iPad2 上使用最新版本的 Chrome (15) 和 iOS 5 进行测试。 这是我正在使用的代码:
<html>
<head>
<script src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
<script>
$(document).ready(function(){
$("#myVideoTag").on('ended', function(){
webkitExitFullScreen();
});
});
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>854x480</title>
</head>
<body>
<video width="854" height="480"
src="video/854x480-Template_1.mp4"
poster="images/poster.jpg"
id="myVideoTag"
type="video/mp4"
preload="auto"
autobuffer
controls>
<p>Requires HTML5 capable browser.</p>
</video>
</body>
</html>
任何帮助将不胜感激。
最佳答案
webkitExitFullScreen
是 video
元素的一个方法,因此必须这样调用:
videoElement.webkitExitFullscreen();
//or
$("#myVideoTag")[0].webkitExitFullscreen();
//or, without needing jQuery
document.getElementsById('myVideoTag').webkitExitFullscreen();
由于它位于事件处理程序内,因此 this
将是结束
的视频
,因此:
$("#myVideoTag").on('ended', function(){
this.webkitExitFullscreen();
});
<小时/>
它变得有点复杂,因为 webkitExitFullscreen
仅适用于基于 webkit 的浏览器(Safari、Chrome、Opera),因此您可以在 MDN 上了解有关其正确用法的更多信息。
关于jquery - 使用 HTML5 视频标签退出全屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8174208/