Sho*_*wer 10 jquery fullscreen exit ipad html5-video
我试图让视频在视频结束时退出全屏,但事实并非如此.我搜索并找到了做到这一点的方法,但对于我的生活,我无法让它发挥作用.我正在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>
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
cba*_*rri 16
webkitExitFullScreen
是video
元素的方法,因此必须以这种方式调用:
videoElement.webkitExitFullscreen();
//or
$("#myVideoTag")[0].webkitExitFullscreen();
//or, without needing jQuery
document.getElementsById('myVideoTag').webkitExitFullscreen();
Run Code Online (Sandbox Code Playgroud)
因为它在事件处理程序中,所以this
就是video
这样ended
,所以:
$("#myVideoTag").on('ended', function(){
this.webkitExitFullscreen();
});
Run Code Online (Sandbox Code Playgroud)
它变得有点复杂,因为webkitExitFullscreen
只适用于基于webkit的浏览器(Safari,Chrome,Opera),因此您可以在MDN上了解有关其正确用法的更多信息
我知道已经解决了这个问题,但这是我最终在所有浏览器结束后关闭全屏视频时使用的小代码段。
目前可在Chrome,IE11,Firefox上运行:
$("#myVideoTag").on('ended', function(){
if (document.exitFullscreen) {
document.exitFullscreen(); // Standard
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen(); // Blink
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen(); // Gecko
} else if (document.msExitFullscreen) {
document.msExitFullscreen(); // Old IE
}
});
Run Code Online (Sandbox Code Playgroud)
您还可以找到当前的全屏元素(如果有),例如:
var fullscreenElement = document.fullscreenElement ||
document.mozFullScreenElement || document.webkitFullscreenElement;
Run Code Online (Sandbox Code Playgroud)
资料来源:https : //www.sitepoint.com/use-html5-full-screen-api/
我只是想添加答案,因为这是我在寻找解决方案时遇到的第一个问题。
归档时间: |
|
查看次数: |
19610 次 |
最近记录: |