移动端页面防止左右滑动出现黑色背景
2016-12-17 14:09
253 查看
<meta name="x5-fullscreen" content="true">
<meta name="full-screen" content="yes">
在head中加入如上2条代码,将页面设置成全屏模式
//监听手指滑动触发事件,设置系统对左右滑动事件不做出处理。
window.onload=function(){
var xx, yy, XX, YY, swipeX, swipeY;
var div = document.getElementsByTagName("div");
document.body.addEventListener('touchstart', function(event) {
xx = event.targetTouches[0].screenX;
yy = event.targetTouches[0].screenY;
swipeX = true;
swipeY = true;
})
document.body.addEventListener('touchmove', function(event) {
XX = event.targetTouches[0].screenX;
YY = event.targetTouches[0].screenY;
if (swipeX && Math.abs(XX - xx) - Math.abs(YY - yy) > 0) //左右滑动
{
event.stopPropagation();//组织冒泡
event.preventDefault();//阻止浏览器默认事件
swipeY = false;
//左右滑动
} else if (swipeY && Math.abs(XX - xx) - Math.abs(YY - yy) < 0) { //上下滑动
swipeX = false;
//上下滑动,使用浏览器默认的上下滑动
}
})
}
<meta name="full-screen" content="yes">
在head中加入如上2条代码,将页面设置成全屏模式
//监听手指滑动触发事件,设置系统对左右滑动事件不做出处理。
window.onload=function(){
var xx, yy, XX, YY, swipeX, swipeY;
var div = document.getElementsByTagName("div");
document.body.addEventListener('touchstart', function(event) {
xx = event.targetTouches[0].screenX;
yy = event.targetTouches[0].screenY;
swipeX = true;
swipeY = true;
})
document.body.addEventListener('touchmove', function(event) {
XX = event.targetTouches[0].screenX;
YY = event.targetTouches[0].screenY;
if (swipeX && Math.abs(XX - xx) - Math.abs(YY - yy) > 0) //左右滑动
{
event.stopPropagation();//组织冒泡
event.preventDefault();//阻止浏览器默认事件
swipeY = false;
//左右滑动
} else if (swipeY && Math.abs(XX - xx) - Math.abs(YY - yy) < 0) { //上下滑动
swipeX = false;
//上下滑动,使用浏览器默认的上下滑动
}
})
}
相关文章推荐
- 移动端页面防止左右滑动出现黑色背景
- 移动端页面防止左右滑动出现黑色背景
- 移动端页面防止左右滑动出现黑色背景
- 移动端页面防止左右滑动出现黑色背景
- 移动端页面防止左右滑动出现黑色背景
- 移动端页面防止左右滑动出现黑色背景
- 移动端页面防止左右滑动出现黑色背景
- 移动端页面防止左右滑动出现黑色背景
- 移动端页面防止左右滑动出现黑色背景
- 移动端页面防止左右滑动出现黑色背景
- 如何解决iphone手机微信浏览器中滑动到页面底部出现黑色背景盖住position:fixed的页面元素的问题?
- ListView滑动时 item出现黑色背景的问题的解决方法
- android ListView控件滑动时出现黑色背景问题解法方案
- ViewFlipper 在同一背景下 页面左右滑动
- listview中item 有checkbox多选防止滑动 listview页面 出现checkbox错位问题
- 移动端、移动开发 点击事件后出现闪或者黑色背景
- listview中item 有checkbox多选防止滑动 listview页面 出现checkbox错位问题
- UIWebView隐藏右侧和底部滚动条,去掉滚动边界的黑色背景,禁止左右滑动
- ListView滑动时 item出现黑色背景的问题的解决方法
- 关于移动端点击后出现闪或者黑色背景