Tôi chỉ cần tránh di chuyển trên thiết bị di động bằng JS và/hoặc JQuery khi xảy ra một sự kiện nhất định. Tôi có một hình, khi người dùng mở hình, cuộn sẽ bị vô hiệu hóa, khi nó được đóng lại, việc cuộn sẽ được bật lại. thiết bị mục tiêu là:Ngăn việc di chuyển trên điện thoại thông minh với kích thước màn hình cụ thể
- bất kỳ IPhone 4s từ lên đến mới nhất một (5 + 6 bao gồm)
Dưới đây là một số trong những điều mà tôi đã cố gắng nhưng đã không làm việc ra:
Method1:
document.addEventListener('touchstart', this.touchstart);
document.addEventListener('touchmove', this.touchmove);
function touchstart(e) {
e.preventDefault()
}
function touchmove(e) {
e.preventDefault()
}
Cách 2:
// left: 37, up: 38, right: 39, down: 40,
// spacebar: 32, pageup: 33, pagedown: 34, end: 35, home: 36
var keys = {37: 1, 38: 1, 39: 1, 40: 1};
function preventDefault(e) {
e = e || window.event;
if (e.preventDefault)
e.preventDefault();
e.returnValue = false;
}
function preventDefaultForScrollKeys(e) {
if (keys[e.keyCode]) {
preventDefault(e);
return false;
}
}
function disableScroll() {
if (window.addEventListener) // older FF
window.addEventListener('DOMMouseScroll', preventDefault, false);
window.onwheel = preventDefault; // modern standard
window.onmousewheel = document.onmousewheel = preventDefault; // older browsers, IE
window.ontouchmove = preventDefault; // mobile
document.onkeydown = preventDefaultForScrollKeys;
}
function enableScroll() {
if (window.removeEventListener)
window.removeEventListener('DOMMouseScroll', preventDefault, false);
window.onmousewheel = document.onmousewheel = null;
window.onwheel = null;
window.ontouchmove = null;
document.onkeydown = null;
}
Có đề xuất nào khác không?
tiếc là không hoạt động trên các thiết bị, nó hoạt động tốt trên tho máy tính xách tay như các phương pháp mà tôi đã đề cập ở trên. Bất cứ một đề nghị nào khác? –