分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

js获取浏览器缩放比例

发布时间:2023-09-06 01:55责任编辑:傅花花关键词:js浏览器

前几天在做项目的时候遇到浏览器缩放比例不为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;};

推荐地址:http://www.jb51.net/article/55753.htm

js获取浏览器缩放比例

原文地址:https://www.cnblogs.com/xiaoyaoxingchen/p/9057387.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved