首页 > 其他分享 >禁止鼠标滑轮缩放页面

禁止鼠标滑轮缩放页面

时间:2022-11-17 15:00:17浏览次数:57  
标签:ratio 鼠标 缩放 screen undefined window var 滑轮

1、在页面挂载钩子中写入,全局App文件

 this.keepRatio()     window.addEventListener('resize', () => {       this.keepRatio()     });   2、定义禁止缩放函数 keepRatio() {       var ratio = 0 // 定义一个缩放比例       var screen = window.screen // 获取窗口对象       var 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)       }       this.ratio = (ratio / 100).toFixed(2)       document.body.style.zoom = 1 / this.ratio // 窗口视图除以缩放比例:即缩放还原     }

标签:ratio,鼠标,缩放,screen,undefined,window,var,滑轮
From: https://www.cnblogs.com/zj6666/p/16899504.html

相关文章