浏览器缩放检测的js代码


Posted in Javascript onSeptember 28, 2014

测试代码

http://jsbin.com/dipijeqi/11

效果:

chrome

window.devicePixelRatio : 2  (准确)

screen.deviceXDPI / screen.logicalXDPI : NaN

window.outerWidth / window.innerWidth : 2

document.documentElement.offsetHeight / window.innerHeight : 0.020618556701030927 (有相关性)

window.top.outerWidth / window.top.innerWidth : 2

ff

window.devicePixelRatio : 1.5 (准确)

screen.deviceXDPI / screen.logicalXDPI : NaN

window.outerWidth / window.innerWidth : 1.0114583333333333

document.documentElement.offsetHeight / window.innerHeight : 0.023391812865497075  (有相关性)

window.top.outerWidth / window.top.innerWidth : 1.0114583333333333

ie 8

window.devicePixelRatio : undefined

screen.deviceXDPI / screen.logicalXDPI : 1.5416666666666667 (大致准确)

window.outerWidth / window.innerWidth : NaN

document.documentElement.offsetHeight / window.innerHeight : NaN

window.top.outerWidth / window.top.innerWidth : NaN

ie11

window.devicePixelRatio : 1.5 (准确)

screen.deviceXDPI / screen.logicalXDPI : 1.5

window.outerWidth / window.innerWidth : 1.0084033613445377

document.documentElement.offsetHeight / window.innerHeight : 0.02203856749311295 (有相关性)

window.top.outerWidth / window.top.innerWidth : 1.0084033613445377

ie10

window.devicePixelRatio : undefined

screen.deviceXDPI / screen.logicalXDPI : 1.5 (准确)

window.outerWidth / window.innerWidth : 1.0084033613445377

document.documentElement.offsetHeight / window.innerHeight : 1

window.top.outerWidth / window.top.innerWidth : 1.0084033613445377

ie9

window.devicePixelRatio : undefined

screen.deviceXDPI / screen.logicalXDPI : 1.5 (准确)

window.outerWidth / window.innerWidth : 1.0084033613445377

document.documentElement.offsetHeight / window.innerHeight : 1

window.top.outerWidth / window.top.innerWidth : 1.0084033613445377

360 6.3(完全没反应)

window.devicePixelRatio : undefined

screen.deviceXDPI / screen.logicalXDPI : 1

window.outerWidth / window.innerWidth : NaN

document.documentElement.offsetHeight / window.innerHeight : NaN

window.top.outerWidth / window.top.innerWidth : NaN

360极速浏览器

window.devicePixelRatio : 1

screen.deviceXDPI / screen.logicalXDPI : NaN

window.outerWidth / window.innerWidth : 1.5

document.documentElement.offsetHeight / window.innerHeight : 0.015267175572519083

window.top.outerWidth / window.top.innerWidth : 1.5(准确)

搜狗高速浏览器 (完全没反应)

window.devicePixelRatio : undefined

screen.deviceXDPI / screen.logicalXDPI : 1

window.outerWidth / window.innerWidth : NaN

document.documentElement.offsetHeight / window.innerHeight : NaN

window.top.outerWidth / window.top.innerWidth : NaN

淘宝浏览器

window.devicePixelRatio : 1

screen.deviceXDPI / screen.logicalXDPI : NaN

window.outerWidth / window.innerWidth : 2.0710059171597632  (大致准确)

document.documentElement.offsetHeight / window.innerHeight : 0.022988505747126436

window.top.outerWidth / window.top.innerWidth : 2.0710059171597632
Javascript 相关文章推荐
Web层改进II-用xmlhttp 无声息提交复杂表单
Jan 22 Javascript
jquery无刷新验证邮箱地址实现实例
Feb 19 Javascript
JavaScript中的ArrayBuffer详细介绍
Dec 08 Javascript
深入理解Java线程编程中的阻塞队列容器
Dec 07 Javascript
浅谈jQuery中Ajax事件beforesend及各参数含义
Dec 03 Javascript
超全面的javascript中变量命名规则
Feb 09 Javascript
jQuery实现的简单在线计算器功能
May 11 jQuery
Vue项目中quill-editor带样式编辑器的使用方法
Aug 08 Javascript
jQuery判断网页是否已经滚动到浏览器底部的实现方法
Oct 27 jQuery
实战node静态文件服务器的示例代码
Mar 08 Javascript
在vue使用clipboard.js进行一键复制文本的实现示例
Jan 15 Javascript
Vue scoped及deep使用方法解析
Aug 01 Javascript
排序算法的javascript实现与讲解(99js手记)
Sep 28 #Javascript
Javascript中封装window.open解决不兼容问题
Sep 28 #Javascript
jQuery固定浮动侧边栏实现思路及代码
Sep 28 #Javascript
js文件包含的几种方式介绍
Sep 28 #Javascript
javascript中bind函数的作用实例介绍
Sep 28 #Javascript
js和jquery如何获取图片真实的宽度和高度
Sep 28 #Javascript
一个jquery实现的不错的多行文字图片滚动效果
Sep 28 #Javascript
You might like
国产动画《伍六七》原声大碟大卖,啊哈娱乐引领音乐赋能IP的新尝试
2020/03/08 国漫
关于手调机和数调机的选择
2021/03/02 无线电
PHP实现分页的一个示例
2006/10/09 PHP
PHP类中Static方法效率测试代码
2010/10/17 PHP
PHP发明人谈MVC和网站设计架构 貌似他不支持php用mvc
2011/06/04 PHP
PHP中如何定义和使用常量
2013/02/28 PHP
PHP+apc+ajax实现的ajax_upload上传进度条代码
2016/01/25 PHP
解决php 处理 form 表单提交多个 name 属性值相同的 input 标签问题
2017/05/11 PHP
PHP实现的贪婪算法实例
2017/10/17 PHP
PHP实现数组根据某个单元字段排序操作示例
2018/08/01 PHP
javascript实现轮显新闻标题链接
2007/08/13 Javascript
一个封装js代码-----展开收起效果示例
2013/07/03 Javascript
JavaScript中对循环语句的优化技巧深入探讨
2014/06/06 Javascript
JS实现选中当前菜单后高亮显示的导航条效果
2015/10/15 Javascript
JavaScript 判断一个对象{}是否为空对象的简单方法
2016/10/09 Javascript
jQuery中的deferred对象和extend方法详解
2017/05/08 jQuery
vue实现消息的无缝滚动效果的示例代码
2017/12/05 Javascript
利用vue组件自定义v-model实现一个Tab组件方法示例
2017/12/06 Javascript
vue缓存之keep-alive的理解和应用详解
2020/11/02 Javascript
vue 判断两个时间插件结束时间必选大于开始时间的代码
2020/11/04 Javascript
关于angular 8.1使用过程中的一些记录
2020/11/25 Javascript
[39:53]完美世界DOTA2联赛PWL S2 LBZS vs Forest 第一场 11.19
2020/11/19 DOTA
使用XML库的方式,实现RPC通信的方法(推荐)
2017/06/14 Python
python中map()函数的使用方法示例
2017/09/29 Python
python使用邻接矩阵构造图代码示例
2017/11/10 Python
tensorflow中next_batch的具体使用
2018/02/02 Python
python opencv之分水岭算法示例
2018/02/24 Python
Python3模拟curl发送post请求操作示例
2019/05/03 Python
调整Jupyter notebook的启动目录操作
2020/04/10 Python
Django中ORM找出内容不为空的数据实例
2020/05/20 Python
8种常用的Python工具
2020/08/05 Python
美国专注于健康商品的网站:eVitamins
2017/01/23 全球购物
Linux如何为某个操作添加别名
2013/03/01 面试题
会计员岗位职责
2014/03/15 职场文书
经营理念口号
2014/06/21 职场文书
python单向链表实例详解
2022/05/25 Python