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

react-use-zoom

v1.0.12

Published

Nearly native image scaling in web (mobile/desktop), rich in functionality. This will make your mobile users happy

Downloads

8

Readme

react-use-zoom

Nearly native image scaling (:iphone:/:computer:), rich in functionality. It is extremely easy to use. it's built by comparing scaling features existing in 'Gallery' apps for smartphones. It doesn't seem slow, but it doesn't seem ridiculously fast either, to be honest, I didn't measure performance. This will also boost your mobile app and website user experience.

Preview

Note

The image must take up the entire width and height of the page

Features


Mobile

  • Pinch
  • Pan
  • Touch move

Desktop

  • Mouse wheel
  • Mouse move

General

  • Maximum scaling value calculated automatically
  • The image is limited by its border
  • It is lightweight
  • It feels "native"

Installation

via NPM
npm i react-use-zoom
via CDN (unpkg)
https://unpkg.com/react-use-zoom@latest/build/index.umd.js

UMD library exposed as reactUseZoom

Usage

It is also very important that your image contains the following css properties.

.img {
  width: 100%;
  height: 100%;
  will-change: transform;
  backface-visibility: hidden;
  touch-action: none;
  transform-origin: 0 0;
  position: absolute;
  -webkit-user-drag: none;
  user-drag: none;
}

.basic-transition {
  transition: all 0.2s;
}
import { useZoom } from "react-use-zoom";

const MyComponent = () => {
  const { imgRef, fit, events } = useZoom({
    transitionClassName: "basic-transition",
  });
  return (
    <img
      className="img"
      src={"..."}
      ref={imgRef}
      style={{ objectFit: fit }}
      {...events}
    />
  );
};

Manual zooming

If for some reason you want to zoom in by calling the function manually. You can use the zoomIn and zoomOut functions. It will scale in the center of the image.

import { useZoom } from "react-use-zoom";

const MyComponent = () => {
const { imgRef, fit, events, `zoomIn`, `zoomOut` } = useZoom();
const handleInZoom = () => `zoomIn()`;
const handleOutZoom = () => `zoomOut()`;
};

API useZoom

| Prop | Type | Description | | ------------------- | --------------------------------------------- | ------------------------------------------------------------------------------------------------ | | events | React.TouchEvent,React.MouseEvent,Event | Events must be assigned to an element to work with it. onLoad, onMouseDown or onTouchStart | | zoomIn | Function | Call the zoom in manually. The transformation point will be at the center | | zoomOut | Function | Call the zoom out manually. The transformation point will be at the center | | fit | React.CSSProperties | Decides when the image should be object-fit: contain;' or 'object-fit: none;' | |visibility|React.CSSProperties| Thevisibilityproperty specifies whether or not an element is visible. This is mainly done to remove flickering from the image. | imgRef |React.RefObject | Access an image by providing a reference | | transitionClassName |String` | Class name to provide a smooth transition when scaling |