Socket
Socket
Sign inDemoInstall

react-fast-pinch-zoom

Package Overview
Dependencies
6
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-fast-pinch-zoom

[![Code quality](https://github.com/retyui/react-fast-pinch-zoom/actions/workflows/nodejs.yml/badge.svg)](https://github.com/retyui/react-fast-pinch-zoom/actions/workflows/nodejs.yml) [![react-fast-pinch-zoom on npm](https://badgen.net/npm/v/react-fast-pi


Version published
Weekly downloads
12
decreased by-40%
Maintainers
1
Install size
47.4 kB
Created
Weekly downloads
 

Changelog

Source

1.1.0

  • Add peerDependenciesMeta for npm@7
  • Use es2015 target for ESM
  • TS: type => interface
  • TS: update to latest version
  • TS: use @tsconfig/create-react-app instead own config
  • Update devDependencies
  • Add tests

Readme

Source

<PinchZoom/> - a react component for pinch zooming DOM elements.

Code quality react-fast-pinch-zoom on npm react-fast-pinch-zoom downloads react-fast-pinch-zoom bundle size

This is a migration of GoogleChromeLabs/pinch-zoom to React!

Demo

Simple image pinch-zoom. Although you can put any element in <PinchZoom/>.

Usage

yarn add pinch-zoom-element
import React, { useRef, useCallback } from "react";
import {
  PinchZoom,
  applyCssProperties,
  getTransform3DValue,
  getTransform2DValue,
} from "react-fast-pinch-zoom";

const App = () => {
  const ref = useRef(null);
  const onTransform = useCallback(({ x, y, scale }) => {
    // Use CSS Custom Properties (Variables)
    applyCssProperties(ref.current, { x, y, scale });

    // Or use literal transform value
    // ref.current.style.setProperty('transform',getTransform3DValue({x,y,scale}));
    // ref.current.style.setProperty('transform',getTransform2DValue({x,y,scale}));
  }, []);

  return (
    <PinchZoom onTransform={onTransform}>
      <img
        ref={ref}
        alt="two black cats look at you"
        src="https://cdn.glitch.com/d824d0c2-e771-4c9f-9fe2-a66b3ac139c5%2Fcats.jpg"
      />
    </PinchZoom>
  );
};

Now the above can be pinch-zoomed!

API

const App = () => {
  const pinchZoomRef = React.useRef();

  return (
    <PinchZoom ref={pinchZoomRef}>
      <img />
    </PinchZoom>
  );
};

Properties

pinchZoomRef.current.x; // x offset
pinchZoomRef.current.y; // y offset
pinchZoomRef.current.scale; // scale

Methods

Set the transform. All values are optional.

pinchZoomRef.current.setTransform({
  scale: 1,
  x: 0,
  y: 0,
});

Scale in/out of a particular point.

const scale = 2;

pinchZoomRef.current.scaleTo(scale, {
  // Transform origin. Can be a number, or string percent, eg "50%"
  originX: 0,
  originY: 0,
  // Should the transform origin be relative to the "container", or "content"?
  relativeTo: "content",
});

Keywords

FAQs

Last updated on 19 Oct 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc