如何在所有现代浏览器中检测页面缩放级别?如何在所有现代浏览器中检测页面缩放级别?而这个螺纹在IE7和IE8中,我无法找到一个很好的跨浏览器解决方案。Firefox存储页面缩放级别以供将来访问。在第一页加载时,我能获得缩放级别吗?在我读到的某个地方,当发生缩放更改时,它会工作后页面被加载。有没有办法把'zoom'活动?我需要这个,因为我的一些计算是基于像素的,它们可能在缩放时波动。@TfL提供的修改样本此页面在缩放时提醒不同的高度值。[jsFiddle]<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js" type="text/javascript"/></script>
</head>
<body>
<div id="xy" style="border:1px solid #f00; width:100px;">Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Pellentesque sollicitudin tortor in lacus tincidunt volutpat. Integer dignissim imperdiet mollis. Suspendisse quis
tortor velit, placerat tempor neque. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Praesent bibendum auctor lorem vitae tempor. Nullam condimentum aliquam elementum. Nullam egestas gravida elementum.
Maecenas mattis molestie nisl sit amet vehicula. Donec semper tristique blandit. Vestibulum adipiscing placerat mollis.</div>
<button onclick="alert($('#xy').height());">Show</button>
</body></html>
3 回答
慕勒3428872
TA贡献1848条经验 获得超6个赞
document.width / jQuery(document).width()
document.width / jQuery(document).width()
document.width
window.innerWidth
window.outerWidth
var screenCssPixelRatio = (window.outerWidth - 8) / window.innerWidth;if (screenCssPixelRatio >= .46 && screenCssPixelRatio <= .54) { zoomLevel = "-4";} else if (screenCssPixelRatio <= .64) { zoomLevel = "-3";} else if (screenCssPixelRatio <= .76) { zoomLevel = "-2";} else if (screenCssPixelRatio <= .92) { zoomLevel = "-1";} else if (screenCssPixelRatio <= 1.10) { zoomLevel = "0";} else if (screenCssPixelRatio <= 1.32) { zoomLevel = "1";} else if (screenCssPixelRatio <= 1.58) { zoomLevel = "2";} else if (screenCssPixelRatio <= 1.90) { zoomLevel = "3";} else if (screenCssPixelRatio <= 2.28) { zoomLevel = "4";} else if (screenCssPixelRatio <= 2.70) { zoomLevel = "5";} else { zoomLevel = "unknown";}
添加回答
举报
0/150
提交
取消