扫码关注官方订阅号
怎么写javascript和html才能禁止网页的上下,左右滚动啊,是在手机浏览器上,onmousewheel=“return false”在PC上有用,但在手机上没用,,用jquery mobile写可以吗?。。急求~~来个实际操作过的大神啊~~
认证高级PHP讲师
你找的是這個嗎?
CSS
overflow: hidden
一种方法:
html头部添加
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
然后将页面body的高度设为window的高度
$("body").height( $(window).height() );
其他方法
页面高度超过设备可见高度时,阻止掉touchmove事件。
document.body.addEventListener('touchmove', function (event) { event.preventDefault(); }, false);
我们都用这个overflow:hidden
加监听事件touchmove,touchstart
头部:
CSS:
html,body{height:100%;overflow:hidden;}
document.addEventListener('touchmove', function(event) { if(event.target.type == 'range') return; event.preventDefault(); })
有个问题,就是使用
document.body.addEventListener('touchmove', function (event) { event.preventDefault(); }, false); 怎么取消?就算使用了移除事件,或者返回 真,都没办法再让页面滚动...有点郁闷.- - 都怪自己太笨...想了下,在阻止默认事件里面加个多条件
javascriptdocument.addEventListener('touchmove', function(event) { //判断条件,条件成立才阻止背景页面滚动,其他情况不会再影响到页面滚动 if(!$(".mask-photo").is(":hidden")){ event.preventDefault(); } })
javascript
document.addEventListener('touchmove', function(event) { //判断条件,条件成立才阻止背景页面滚动,其他情况不会再影响到页面滚动 if(!$(".mask-photo").is(":hidden")){ event.preventDefault(); } })
document.body.addEventListener('touchmove'......
为什么要给body呢?给弹出层就好了
用$("body").bind("touchmove",function(event){event.preventDefault;//code});取消了body的拖动事件。
恢复这个拖动事件只要$("body").unbind("touchmove");
非常实用。
阻止默认 $("body").on("touchmove",function(event){ event.preventDefault; }, false) 然后点击取消或者确定时再取消body上的绑定 $("body").off("touchmove");
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
你找的是這個嗎?
CSS
overflow: hidden
一种方法:
html头部添加
然后将页面body的高度设为window的高度
其他方法
页面高度超过设备可见高度时,阻止掉touchmove事件。
我们都用这个overflow:hidden
加监听事件touchmove,touchstart
头部:
CSS:
有个问题,就是使用
document.body.addEventListener('touchmove'......
为什么要给body呢?给弹出层就好了
用$("body").bind("touchmove",function(event){event.preventDefault;//code});取消了body的拖动事件。
恢复这个拖动事件只要$("body").unbind("touchmove");
非常实用。