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

zoom-gesture

v1.0.1

Published

detects zoom gesture (mouse wheel or pinch) on DOM node

Downloads

7

Readme

Zoom Gesture

npm

npm library that detects zoom gesture (mouse wheel or pinch) on DOM node

Example

import ZoomGesture from 'zoom-gesture';

const zoomNode = document.querySelector('.zoom');
const zoomHandler = new ZoomGesture({
  element: zoomNode,
  minScale: 1,
  maxScale: 2,
  // read more about options below
});
const fn = zoom => { /* some things with zoom */ };

zoomHandler.on('change', fn);
zoomHandler.init();
// read more about methods below

Options

element

DOM node where you need to detect zoom gesture.

Default: window.

initScale

Init value of scale.

Default: 1.

wheelScaleSize

Amount of pixels that user must scroll by mouse or touchpad to change scale value by 1.

Default: 300.

touchScaleSize

Amount of pixels that user must move (pinch) by touch pointers (fingers, etc) using to change scale value by 1.

Default: undefined.

Note: there is no default value, because default behaviour is slightly different.

By default when user starts to do pinch gesture, the library counts distance between touch points and when it doubles — the library increases scale value by 1 (when it is tripled — by 2, etc).

minScale

Minimum value of scale.

Default: undefined.

Note: undefined value (or any other non-numeric) value means that scale value may be negative.

maxScale

Maximum value of scale.

Default: undefined.

Methods

init

Use it to initialize all listeners.

destroy

Use it to remove all listeners.

setScale

Use it to set scale value manually, it you need it.

Note: the library does not check value that you set using this method by range of possible values (that you can set by minScale and maxScale), but it triggers listeners of change event.

Arguments:

  • scale (numeric).

on

Use it to add listeners for the library events.

Right now there is only one event — change. Read about it below.

Arguments:

  • event (string);
  • fn (func).

off

Use it to remove listeners for the library events.

Right now there is only one event — change. Read about it below.

Arguments:

  • event (string);
  • fn (func).

Events

change

Handlers for this event are called when scale value is changed by user's zoom gesture.

Parameters passed to handler:

  • scale (numeric).

Why?

Sometimes I need to implement some things where I need to detect zoom gesture and do something depends on it. For example, image editor where you can change zoom of selected image.