解决 ios10 及以上 Safari 无法禁止缩放的问题
/**
*
* 解决 ios10 及以上 Safari 无法禁止缩放的问题
* */
function handleUserNoScalable() {
window.onload = function() {
// 阻止双击放大
var lastTouchEnd = 0
document.addEventListener('touchstart', function(event) {
if (event.touches.length > 1) {
event.preventDefault()
}
})
document.addEventListener(
'touchend',
function(event) {
var now = new Date().getTime()
if (now - lastTouchEnd <= 300) {
event.preventDefault()
}
lastTouchEnd = now
},
false
)
// 阻止双指放大
document.addEventListener('gesturestart', function(event) {
event.preventDefault()
})
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
编辑 (opens new window)
上次更新: 2021/08/31 10:01:53