first step:
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" />
The second step:
window.onload = function () {
document.addEventListener('gesturestart', function (e) {
e.preventDefault();
});
//以上是禁止双指缩放
//以下是禁止双击缩放
document.addEventListener('touchstart', function (e) {
if (e.touches.length > 1) {
e.preventDefault();
}
});
var endTouch = 0;
document.addEventListener('touchend', function (e) {
var nowTouch = (new Date()).getTime();
if (nowTouch - endTouch<= 300) { //为什么是300,看注意
e.preventDefault();
}
endTouch = nowTouch ;
}, false);
};
Note:
Click penetration problem: the mobile terminal click will have a delay of about 300ms than touchstart/touchend. The browser will wait 300ms after the click to determine whether the user clicks multiple times. If there are multiple clicks within 300ms, it will be judged as not a click event.