Giter VIP home page Giter VIP logo

zoom-level's Introduction

zoom-level

NPM Version NPM Downloads NPM Dependents Build Types Tree Shaking

× LIVE EXAMPLE ×


ABOUT

This plugin allows you to detect browser's and separate element's zoom level.
It is lightweight and has no dependencies!

INSTALLATION

npm install zoom-level
# or via yarn
yarn add zoom-level

INSTALLATION NOTE:
This lib is written in ES6+ and delivering with both, transpiled and untranspiled versions:

  • main field of package.json is pointing ES5 with CJS modules resolution;
  • module field is pointing to ES5 with ES modules resolution;
  • esnext field is pointing to ESNext with ES modules resolution;

Depending on your targets you may have to use Webpack and/or Babel to pull untranspiled version of package.
See some tips on wiring thing up: https://2ality.com/2017/06/pkg-esnext.html

USAGE

import zoomLevel from "zoom-level";

zoomLevel(); // 1;

window.addEventListener("resize", () => {
  zoomLevel(); // will return current browser's zoom level
});

Or, in case you want to detect separate element's zoom level (they can use own zoom CSS property which stacks with browser's one);

import { elementZoomLevel } from "zoom-level";

const zoomedBlock = document.createElement("div");
zoomedBlock.style.zoom = 0.5;
zoomedBlock.style.width = "150px";
zoomedBlock.style.height = "150px";
zoomedBlock.style.margin = "32px";
zoomedBlock.style.padding = "32px";
zoomedBlock.style.background = "rgba(0,0,0,.05)";
zoomedBlock.innerText = "Lorem ipusm dolor sit amet";
document.appendChild(zoomedBlock);

elementZoomLevel(zoomedBlock); // 0.5;

window.addEventListener("resize", () => {
  elementZoomLevel(zoomedBlock); // if you zoom to 200% it'll be 1
});

TESTS

Sadly i have no idea how to manage testing of this package, due to there is no known ways to control browser's zoom level.
If you know how to do it - please let me know.

Related projects

zoom-level's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar semantic-release-bot avatar xobotyi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

zoom-level's Issues

Does not work on mobile / pinching?

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
When you zoom/pinch in on mobile the zoom level does not update

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have extra dependencies other than zoom-level. Paste the link to your JSFiddle or CodeSandbox example below:

https://www.loom.com/share/6aa27b335cdf4adeb916187f9b3f3ec9

https://codesandbox.io/s/zoomlevel-live-example-841ns

What is the expected behavior?

Zoom level should change when pinching in

Doesn't work in Safari

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
Doesn't work in Safari

What is the expected behavior?
I'd expect it to work in Safari

Which versions of zoom-level, and which browser / OS / node version are affected by this issue? Did this work in previous versions of zoom-level?
I'm testing on https://841ns.csb.app in Safari 13.0.4 on Mac 10.14.6. Nothing happens when I zoom in or out of the page, even after clicking the Recalc button. Works as expected in Chrome.

Wrong values in retina vs other displays

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
Retina displays will always have values double that of regular displays. I am only interested in desktop, as I anticipate mobile is much more difficult.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have extra dependencies other than zoom-level. Paste the link to your JSFiddle or CodeSandbox example below:
I am looking at https://codesandbox.io/s/zoomlevel-live-example-841ns / https://841ns.csb.app/, as well as testing in the console.

What is the expected behavior?
Ideally a retina display can be identified and its value halved so that retina and non-retina displays give the same value.

Which versions of zoom-level, and which browser / OS / node version are affected by this issue? Did this work in previous versions of zoom-level?
zoom-level: Latest
Browser: Chrome 81.0.4044.122 / FF 75.0
OS: MBP 16 on 10.15.

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.