npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

detect-zoom

v1.0.2

Published

Cross Browser Zoom and Pixel Ratio Detector

Downloads

7,469

Readme

Cross Browser Zoom and Pixel Ratio Detector


Known issues:

  • In Firefox on retina displays (Macbook Pros), the base zoom level is always 2.0. I'm aware of it and looking for a solution.
  • Some desktop input devices like Wacom tablets add "mobile like" touch events which break the feature detection I'm using and gives false zoom level results. Working on a better way to detect these.
  • In some multi-monitor enviroments where each monitor has a different 'pixel aspect ratio' windows that span accross both monitors might return false pixelAspectRatio values.

What is this for?

Detecting the browser zoom level and device pixel ratio relative to the zoom level.

It can be used to show higher-resolution canvas or img when necessary, to warn users that your site's layout will be broken in their current zoom level, and much more. Personally I'm maintaining it to use Detect-zoom in Wix.com's editor to warn users that their browser is in zoom mode before saving important changes to their website.

What happend to @yonran?

Don't worry, he is well. As of January 2013 @yonran stopped maintaining his source of detect-zoom, and transferred the repository to me. If you are looking to update previous versions note that there were some breaking changes

  • Major Changes from the latest yonran version:
    • DetectZoom object name changed to detectZoom
    • DetectZoom.ratio() is no longer publicly accessible
    • Supported browsers: IE8+, FF4+, modern Webkit, mobile Webkit, Opera 11.1+
    • IE6, IE7, FF 3.6 and Opera 10.x are no longer supported
    • Added support to be loaded as an AMD and CommonJS module

Live Example

See the Live Example section in http://tombigel.github.com/detect-zoom/

Usage

Detect-zoom has only two public functions:

  • zoom() Returns the zoom level of the user's browser using Javascript.
  • device() Returns the device pixel ratio multiplied by the zoom level (Read more about devicePixelRatio at QuirksMode)
<script src="detect-zoom.js"></script>
<script>
  var zoom = detectZoom.zoom();
  var device = detectZoom.device();

  console.log(zoom, device);
</script>

AMD Usage

require(['detect-zoom'], function(detectZoom){
    var zoom = detectZoom.zoom();
});

Changelog

2013/3/29

  • Added package.json (thanks @TCampaigne)
  • Some documentation fixes

2013/2/25

  • Fixed a missing 'else' between ie8 and ie10 detection
  • Minor version bump to 1.0.2

2013/2/15

  • Added a fix for IE10 Metro (or whatever MS calls it these days..) by @stefanvanburen
  • Minor version bump to 1.0.1
  • Added minimized version

2013/2/05

  • Merged a pull request that fixed zoom on IE being returned X100 (thanks @kreymerman)
  • Refactored the code some more, changed some function names
  • Browser dependent main function is created only on initialization (thanks @jsmaker)
  • Open Issue: Firefox returns zoom and devicePixelRatio the same. Still looking for a solution here.
  • Started versioning - this is version 1.0.0

2013/1/27

  • Added a fix to Mozilla's (Broken as I see it - https://bugzilla.mozilla.org/show_bug.cgi?id=809788) implementation of window.devicePixel starting Firefox 18

2013/1/26

  • Repository moved here
  • Refactored most of the code
  • Removed support for older browsers
  • Added support for AMD and CommonJS

Help Needed

Detect-zoom is not complete, many parts of the code are 6 to 12 months old and I'm still reviewing them I need help testing different browsers, finding better ways to measure zoom on problematic browsers (ahm.. Firefox.. ahm) patches are more than welcome.

License

Detect-zoom is dual-licensed under the WTFPL and MIT license, at the recipient's choice.