Last Updated: February 25, 2016
·
445
· ivanovb

Monitoring the zoom level

In CSS, the left position, if it is expressed in percent for a DOM superior level, is computed based on the width of the viewport.

When the magnification level of the page changes, the width of the viewport remains the same, and also the apparent position of the element with the CSS property left set in percent, while the actual position in pixels will change.

For example, using two elements for marking, one with the absolute position of 0px and one with the absolute position of 10% we can compute the new magnification level like this:

initialBeaconDistance = clientXPosition(beaconTwo) - clientXPosition(beaconOne);

begin onMouseWheel:
        newBeaconDistance = clientXPosition(beaconTwo) - clientXPosition(beaconOne);
        zoom = initialBeaconDistance / newBeaconDistance;
end onMouseWheel

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside