![]() ![]() Unreliable: listen to mouse events and measure change in screenX / change in clientX.This is broken since sometime in 2011 I know no way to get the zoom level in Opera anymore. We use the position:fixed element to get the width of the viewport including the space where the scrollbars are excludes this width. from here ( Quirksmode's widths table says it's a bug innerWidth should be CSS px). Opera: / width of a position:fixed width:100% div.Old WebKit? (unverified): parseInt(getComputedStyle(document.documentElement,null).width) / (from this answer).To get ratio in terms of device pixels (instead of relative to default zoom), multiply by vicePixelRatio. WebKit: (broken since r72591) document.width / jQuery(document).width() (thanks to Dirk van Oosterbosch above).WebKit: measure the preferred size of a div with -webkit-text-size-adjust:none.WebKit: (thanks to Teo in the comments).FF4+: media queries binary search (see below).FF3.5 ONLY: screen.width / media query screen width (see below) (takes advantage of the fact that screen.width uses device pixels but MQ width uses CSS pixels-thanks to Quirksmode widths).IE7: var body = document.body,r = body.getBoundingClientRect() return (r.left-r.right)/body.offsetWidth (thanks to this example or this answer).IE8: viceXDPI / screen.logicalXDPI (or, for the zoom level relative to default zoom, screen.systemXDPI / screen.logicalXDPI). ![]() I also set up this page to test all these methods of measuring the zoom level.Įdit (): I've added a project that can be cloned: From reading all the responses and blog posts I could find, here's a summary. Now it's an even bigger mess than it was when this question was first asked. Maecenas mattis molestie nisl sit amet vehicula. Praesent bibendum auctor lorem vitae tempor. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Suspendisse quis tortor velit, placerat tempor neque. Pellentesque sollicitudin tortor in lacus tincidunt volutpat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Modified sample given by page alerts different height values when zoomed. I need this because some of my calculations are pixel-based and they may fluctuate when zoomed. On the first page load, would I be able to get the zoom level? Somewhere I read it works when a zoom change occurs after the page is loaded. How can I detect the page zoom level in all modern browsers? While this thread tells how to do it in IE7 and IE8, I can't find a good cross-browser solution.įirefox stores the page zoom level for future access. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |