HTML 禁用移动端双击屏幕缩放页面
最近写项目时发现通过meta标签已无法禁止移动端双指缩放,一般的js写法也无法阻止,最终解决方案如下:
// 禁用缩放 function addMeta() { $('head').append('<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />'); } setTimeout(addMeta, 3000); // 禁用双指放大 document.documentElement.addEventListener('touchstart', function (event) { if (event.touches.length > 1) { event.preventDefault(); } }, { passive: false }); // 禁用双击放大 var lastTouchEnd = 0; document.documentElement.addEventListener('touchend', function (event) { var now = Date.now(); if (now - lastTouchEnd <= 300) { event.preventDefault(); } lastTouchEnd = now; }, { passive: false });
温馨提示 : 非特殊注明,否则均为©李联华的博客网原创文章,本站文章未经授权禁止任何形式转载;IP地址:3.147.66.24,归属地:俄亥俄州Dublin ,欢迎您的访问!
文章链接:https://www.ooize.com/html-disable-the-mobile-terminal-to-double-click-the-screen-to-zoom-the-page.html
文章链接:https://www.ooize.com/html-disable-the-mobile-terminal-to-double-click-the-screen-to-zoom-the-page.html
订阅
登录
0 评论