Skip to content

Commit

Permalink
Prevent default zoom behavior in image preview for browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbvz committed Oct 30, 2019
1 parent 175b3fe commit 31f577e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions extensions/image-preview/media/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
});

container.addEventListener('wheel', (/** @type {WheelEvent} */ e) => {
e.preventDefault();
if (!image || !hasLoadedImage) {
return;
}
Expand All @@ -254,9 +255,11 @@

let delta = e.deltaY > 0 ? 1 : -1;
updateScale(scale * (1 - delta * SCALE_PINCH_FACTOR));
});
}, { passive: false });

window.addEventListener('scroll', e => {
e.preventDefault();

window.addEventListener('scroll', () => {
if (!image || !hasLoadedImage || !image.parentElement || scale === 'fit') {
return;
}
Expand All @@ -265,7 +268,7 @@
if (entry) {
vscode.setState({ scale: entry.scale, offsetX: window.scrollX, offsetY: window.scrollY });
}
});
}, { passive: false });

container.classList.add('image');

Expand Down

0 comments on commit 31f577e

Please sign in to comment.