Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>On Android you can work out the current zoom by adding an absolute div to the body of width 100%, and dividing the div's offsetWidth by <code>window.innerWidth</code>.</p> <pre><code>var iPadMeasureWidthNode = window.iPadWNode; if (!iPadMeasureWidthNode) { iPadMeasureWidthNode = window.iPadWNode = document.createElement('div'); // .ipad-measure-w {position:absolute; width:100%; top:-1px} iPadMeasureWidthNode.className = 'ipad-measure-w'; document.body.insertBefore(iPadMeasureWidthNode, document.body.firstChild); } var zoominverse = 1000 / Math.round(1000 * iPadMeasureWidthNode.offsetWidth / window.innerWidth); </code></pre> <p>You can keep an element at 1:1 zoom by inverting (undoing) the amount of zoom:</p> <pre><code>// Not using scale3d because is hardware zooming which is ugly unreadable blurry pixel magnification. node.style.webkitTransform = (zoominverse &gt; 1) ? 'scale(' + zoominverse + ')' : ''; node.style.webkitTransformOrigin = (zoominverse &gt; 1) ? '0 0 0' : ''; </code></pre> <p>Zoom change is detected by <code>window.onresize</code> event (although resize event is delayed until after resize is completed... you can detect zoom start using the <code>gesturestart</code> event on iPad, or <code>document.touchstart</code> event and detect 2 fingers down).</p> <p>Edit: After three corrections saying it doesn't work, I thought I better add an example showing it working. Tested works on: Android 4.1.2 normal browser, Android 4.1.2 Chrome, Android Opera Mobile 12.10, iPad 2 iOS4. (Didn't work on Android Firefox Mobile, and won't work in an iframe so jsfiddle won't work).</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;style&gt; .ipad-measure-w { position: absolute; width: 100%; top: -1px; }; &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;button onclick="alertWidth()"&gt;alertWidth&lt;/button&gt; &lt;div style="width: 1600px; height: 100px; background-color: blue;"&gt;&lt;/div&gt; &lt;script&gt; function alertWidth() { var iPadMeasureWidthNode = window.iPadWNode; if (!iPadMeasureWidthNode) { iPadMeasureWidthNode = window.iPadWNode = document.createElement('div'); iPadMeasureWidthNode.className = 'ipad-measure-w'; document.body.insertBefore(iPadMeasureWidthNode, document.body.firstChild); } var zoominverse = 1000 / Math.round(1000 * iPadMeasureWidthNode.offsetWidth / window.innerWidth); alert(zoominverse); } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload