daybrush / infinite-viewer

Infinite Viewer is Document Viewer Component with infinite scrolling.
https://daybrush.com/infinite-viewer/
MIT License
283 stars 30 forks source link

Change dragging method #40

Closed leidto closed 1 year ago

leidto commented 1 year ago

useMouseDrag prop is great but I should do the same if the middle mouse button pressed. How can I do this?

anas-araid commented 1 year ago

Same issue: would it be possible to add dragging via the mouse wheel button (like Figma or Miro)? It would be super helpful!

Thanks a lot @daybrush for your hard work on this project!

daybrush commented 1 year ago

@leidto @anas-araid

If wheel button in dragStart event, stop with e.stop function.

viewer.on("dragStart", e => {
     // Abort on wheel button.
     if (e.inputEvent.button === 1) {
        e.stop();
        return;
    }
});
leidto commented 1 year ago

Thanks for your comment @daybrush. I've tried it but doesn't work with the react version. My goal is to use the useMouseDrag property with the mouse middle button not with the left button. I've tried several ways but I can't figure out how it's possible. I can disable the original wheel and scroll event: viewerRef.current.getElement().addEventListener('wheel', (e) => { ... } , but I have to trigger the onDrag method somehow when middle mouse is pressed. I'm stuck.

daybrush commented 1 year ago

@leidto

I'll probably fix it and release it this week.

daybrush commented 1 year ago

@leidto

infinite-viewer's new version is released.

Update and set preventWheelClick to false.

And use:


viewer.on("dragStart", e => {
     // only  allow wheel
     if (e.inputEvent.button !== 1) {
        e.stop();
        return;
    }
});
leidto commented 1 year ago

Thank you. It works perfectly!