/** * 禁止浏览器缩放ctrl + 滚轮/+ — */ function stopZoom() { let zoomText = { '_75': () => { setZoom(0.75) }, '_80': () => { setZoom(0.8) }, '_90': () => { setZoom(0.9) }, '_100': () => { setZoom(1) }, '_110': () => { setZoom(1.1) }, '_125': () => { setZoom(1.25) }, } document.body.addEventListener('keydown', function (e) { if (e.ctrlKey) { let text = getZoom(); (text < 75 || text > 125) && (text = 100); zoomText['_' + text](); } }) } function setZoom (value) { document.body.style.zoom = value; } /** * 获取浏览器缩放百分比 */ function getZoom() { 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; }