js检测浏览器页面是否缩放 发表于 2021-07-27 | 更新于: 2021-07-27 | 阅读数 次 字数统计: 127 字 | 阅读时长 ≈ 1 分钟 使用js前端检测浏览器的页面是否手工缩放 12345678910111213141516171819202122232425262728/** * * detectZoom 函数的返回值如果是 100 就是默认缩放级别,大于 100 则是放大了,小于 100 则是缩小了 **/function detectZoom (){ var ratio = 0, screen = window.screen, ua = navigator.userAgent.toLowerCase(); if (window.devicePixelRatio !== undefined) { ratio = window.devicePixelRatio; } else if (~ua.indexOf('msie')) { if (screen.deviceXDPI && screen.logicalXDPI) { ratio = screen.deviceXDPI / screen.logicalXDPI; } } else if (window.outerWidth !== undefined && window.innerWidth !== undefined) { ratio = window.outerWidth / window.innerWidth; } if (ratio){ ratio = Math.round(ratio * 100); } return ratio;}