retyui / react-quick-pinch-zoom

A react component that providing multi-touch gestures for zooming and dragging on any DOM element.
https://react-quick-pinch-zoom.netlify.app/
312 stars 47 forks source link

How to enable mouse wheel zooming #77

Closed damiano216 closed 1 year ago

damiano216 commented 1 year ago

Hello,

How can I enable mouse wheel zooming without having to hold on the ctrl keyboard button?

Currently I am using the package like this:

import QuickPinchZoom, { make3dTransformValue } from "react-quick-pinch-zoom";
import React, {useRef} from "react";

export default function MyComponent({

const imgRef2 = useRef();

const onUpdate = useCallback(({ x, y, scale }) => {
   const { current: img } = imgRef;
   const value = make3dTransformValue({ x, y, scale });

   img.style.setProperty("transform", value);
  }, []);

return (
 <QuickPinchZoom onUpdate={onUpdate}>
        <img ref={imgRef2} ...../>
  </QuickPinchZoom>
)

)}
retyui commented 1 year ago

use a shouldInterceptWheel pror

const shouldInterceptWheel = event => !(event.ctrlKey || event.metaKey); // default

// but you need always sent true
const shouldInterceptWheel = event => true; // use it
damiano216 commented 1 year ago

Hello,

Using

<QuickPinchZoom
          onUpdate={onUpdate}
          shouldInterceptWheel={(e) => {
            e.ctrlKey || e.metaKey;
          }}
        >

I made zooming work for both the mouse and the laptop touchpad.

Thanks

retyui commented 1 year ago

just for better understanding, your function return nothing

const shouldInterceptWheel = (e) => {
            e.ctrlKey || e.metaKey;
          }

shouldInterceptWheel() // undefined 
damiano216 commented 1 year ago

Yes, the function returns nothing.

But by using it this way, I achieved the desired result to have: -zooming using the laptop touchpad AND -zooming by using the mouse wheel - without having to press any key at the same time

I understand that it may not be a solution as per the official documentation, but it solved our necessities :)