要禁止用户双指放大,可以通过以下3种方法:
- 使用CSS属性:在HTML文档中添加以下CSS属性可以禁止用户双指放大页面内容:
body {
touch-action: none;
user-select: none;
}
- 使用JavaScript:通过JavaScript代码来禁止用户双指放大,可以监听touchstart、touchmove和gesturechange事件,并阻止事件的默认行为。
document.addEventListener('gesturechange', function (e) {
e.preventDefault();
});
- 使用meta标签:在HTML文档的head标签中添加以下meta标签也可以禁止用户双指放大:
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
通过以上方法可以有效地禁止用户双指放大页面内容。