【发布时间】:2011-05-11 20:53:53
【问题描述】:
我正在 Mobile Safari 中编写一个带有视频元素的主屏幕网络应用程序。出于可用性原因,我希望在屏幕上滑动不会使页面滚动。我可以使用以下代码成功防止滑动滚动。但是,如果用户在视频元素上滑动,页面就会滚动。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width; height=device-height; initial-scale=1.0; maximum-scale=1.0; user-scalable=no;"/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<title>no scroll</title>
<script type="text/javascript">
window.onload = function(){
document.addEventListener('touchmove',function(event){
event.preventDefault();
},false);
};
</script>
</head>
<body>
<p>anything but the video will be stationary when swiped.</p>
<video preload="auto" webkit-playsinline id="video" controls height="100" width="100">
<source src="video.mp4" type="video/mp4" />
</video>
</body>
</html>
我已尝试添加代码以防止视频元素吞噬这些事件(插入到 window.onload 函数中):
var videoEl = document.getElementById('video');
videoEl.addEventListener('touchmove',function(event){
event.preventDefault();
},false);
videoEl.addEventListener('touchstart',function(event){
event.preventDefault();
},false);
有解决办法吗?我是否以错误的方式解决问题?
【问题讨论】:
标签: iphone webkit mobile-safari html5-video