[英]Disable Vertical scroll on mobile devices
I am using touchmove
, touchstart
and touchend
functions from JQuery Mobile
. 我正在使用JQuery Mobile
touchmove
, touchstart
和touchend
函数。 I am trying to disable vertical scroll while touchstart
and enable it back when touchend
is triggered. 我试图在touchstart
时禁用垂直滚动,并在触发touchend
时touchend
其重新启用。 I have tried a few things: 我已经尝试了几件事:
Adding overflow: hidden
to body: This works fine for Chrome browser but doesn't work for firefox android 添加overflow: hidden
到身体:这对于Chrome浏览器工作正常,但不适用于Firefox Android
Binding and Unbinding scrolling event to body when touchstart
event fired and touched
fired - Didn't work at all(Im sure I did it wrong). 当touchstart
事件被触发并被touched
时,将滚动事件绑定和touchstart
到正文-根本不起作用(我确定我做错了)。 Below is the code. 下面是代码。
Code: 码:
$(document).on("touchstart", ".amount-container", function(event){
$(".notify-cart").addClass("show");
if(event.touches.length == event.changedTouches.length) {
monitor = {
x: event.touches[0].clientX,
y: event.touches[0].clientY
};
}
}).on("touchend", ".amount-container", function(){
$(".notify-cart").removeClass("show");
$("body").removeClass("overflowhide");
monitor = {};
}).on("touchmove mousemove", ".amount-container", function(event){
if(Math.abs(event.changedTouches[0].clientX - monitor.x) > Math.abs(event.changedTouches[0].clientY - monitor.y)) {
}
else{
event.preventDefault();
}
});
// To Prevent Scrolling while Swipe/touchmove
var touchScroll = function( event ) {
event.preventDefault();
};
I tried few other things too. 我也尝试了其他几件事。 Nothing worked in Firefox. 在Firefox中没有任何工作。 Is there a better way to solve this problem. 有没有更好的方法来解决此问题。 Let me know if you need anything else. 需要帮助请叫我。
I'm not positive this'll work, but try replacing 我不认为这可以解决问题,但请尝试更换
var touchScroll = function( event ) {
event.preventDefault();
};
with 同
document.body.addEventListener('touchstart', function(e){e.preventDefault();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.