GithubHelp home page GithubHelp logo

hhy5277 / detect-zoom Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tombigel/detect-zoom

0.0 1.0 0.0 492 KB

Cross Browser Zoom and Pixel Ratio Detector

Home Page: http://tombigel.github.io/detect-zoom/

Makefile 1.26% JavaScript 98.74%

detect-zoom's Introduction

Cross Browser Zoom and Pixel Ratio Detector


READ THIS: Detect-zoom is currently unusable for desktop

Last update: Aug 7 2013

In the past few months both Mozilla and Google made some changes to their browsers that make it almost impossible to do what detect-zoom is here to do:

Firefox

On Firefox 18 Mozilla changes the devicePixelRatio value on manual zoom (cmd/ctrl +/-), making it impossible to know whether the browser is in zoom mode or is it a retina device, ignoring what the word DEVICE represents.
I personally believe someone there refuses to admit this is a mistake and revert this decision.

Chrome

On Chrome 27 (Meaning WebKit and Blink) webkitTextSizeAdjust was deprecated on desktops versions of the browser. This was the only bullet proof way to detect zoom in desktop chrome that I am aware of.
There are couple of other ways, but they don't cover all the bases - one uses SVG but is not working in iFrames, the other uses window.inner/outerWidth and is not working when there is a sidebar or the DevTools are open on the side.

Other Known issues:

  • 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();
});

Installing with NPM

> npm install detect-zoom

Changelog

2013/4/01

  • Changed WebKit detection from deprecated webkitTextSizeAdjust to webkitMarquee
  • Changed WebKitMobile detection from unreliable 'ontouchstart' event (can be triggered on desktops too) to 'orientation' property that is hopefully more reliable
  • Minor version bump to 1.0.4

2013/3/29

  • Added package.json (thanks @TCampaigne)
  • Some documentation fixes
  • Added detect-zoom to npm package manager (again, thanks @TCampaigne)

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

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.

detect-zoom's People

Contributors

asadnauman avatar balaclark avatar davidchambers avatar devinrhode2 avatar francescobbo avatar iangilman avatar kreymerman avatar kribblo avatar kumar003vinod avatar l-p avatar matthias-m avatar micahwave avatar qtax avatar seyd avatar skeltoac avatar tcampaigne avatar tmcw avatar tombigel avatar yonran avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.