正文 1948字数 409,071阅读


// 浏览器缩放检测 function detectZoom (){ var ratio = 0, screen = window.screen, ua = navigator.userAgent.toLowerCase(); if (window.devicePixelRatio !== undefined) { ratio = window.devicePixelRatio; }else if (~ua.indexOf('msie')) { // ie 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; };
Run code
Cut to clipboard


    let detectZoom=this.detectZoom(); if(100!=detectZoom){ const h = this.$createElement; this.$notify({ title: '警告', message: h('b', { style: 'color: red;font-size:14px;'}, '您的浏览器页面可能处于缩放 ('+detectZoom+'%)状态,这可能引起页面混乱,请尝试按 Ctrl+0 重置后刷新'), duration: 0 }); }
    Run code
    Cut to clipboard


      detectZoom (){ let ratio = 0, screen = window.screen, ua = navigator.userAgent.toLowerCase(); if (window.devicePixelRatio !== undefined) { ratio = window.devicePixelRatio; }else if (~ua.indexOf('msie')) { // ie 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; },
      Run code
      Cut to clipboard