Skip to content

Commit

Permalink
Add pinch events to control zooming (#370)
Browse files Browse the repository at this point in the history
* add zoom and pan to image

* add pinch events on trackpad for zooming
  • Loading branch information
ad12 authored Jun 27, 2023
1 parent b933388 commit 50a76fa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
// Cursor style.
export let cursor: string = 'default';
console.log("Image.svelte: enableZoom = ", zoom);
const handleWheel = (event: WheelEvent) => {
if (!event.ctrlKey) {
return;
}
// Zoom in/out
const { deltaY } = event;
event.preventDefault();
zoom += deltaY * 0.01;
zoom += -deltaY * 0.01;
zoom = Math.max(zoom, 1);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@
}
function handleScroll(event: WheelEvent) {
// Pinch-to-zoom action on MacOS.
// https://dev.to/danburzo/pinch-me-i-m-zooming-gestures-in-the-dom-a0e
if (event.ctrlKey) {
zoom += -event.deltaY * 0.01;
zoom = Math.max(zoom, 1);
return;
}
event.preventDefault();
if (numSlices === 1) {
return;
Expand Down

0 comments on commit 50a76fa

Please sign in to comment.