Skip to content

Commit

Permalink
[BUGFIX] #59 Avoid unintentionally moving the image when dragging
Browse files Browse the repository at this point in the history
  • Loading branch information
deoostfrees committed Jun 5, 2024
1 parent f55616b commit 8e399e6
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 24 deletions.
16 changes: 10 additions & 6 deletions dist/js/parvus.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,8 @@ function Parvus(userOptions) {
* @param {Event} event - The mousedown event object
*/
const mousedownHandler = event => {
event.preventDefault();
event.stopPropagation();
isDraggingX = false;
isDraggingY = false;
pointerDown = true;
Expand All @@ -1118,7 +1120,6 @@ function Parvus(userOptions) {
} = GROUPS[activeGroup];
slider.classList.add('parvus__slider--is-dragging');
slider.style.willChange = 'transform';
event.stopPropagation();
lightboxOverlayOpacity = getComputedStyle(lightboxOverlay).opacity;
};

Expand All @@ -1131,6 +1132,7 @@ function Parvus(userOptions) {
* @param {Event} event - The mousemove event object
*/
const mousemoveHandler = event => {
event.preventDefault();
if (pointerDown) {
const {
pageX,
Expand All @@ -1140,7 +1142,6 @@ function Parvus(userOptions) {
drag.endY = pageY;
doSwipe();
}
event.preventDefault();
};

/**
Expand All @@ -1149,7 +1150,8 @@ function Parvus(userOptions) {
* This function is called when a mouse button is released.
* It handles the necessary actions and logic related to the mouseup event.
*/
const mouseupHandler = () => {
const mouseupHandler = event => {
event.stopPropagation();
pointerDown = false;
const {
slider
Expand All @@ -1171,6 +1173,7 @@ function Parvus(userOptions) {
* @param {Event} event - The touchstart event object
*/
const touchstartHandler = event => {
event.stopPropagation();
isDraggingX = false;
isDraggingY = false;
const {
Expand All @@ -1185,7 +1188,6 @@ function Parvus(userOptions) {
slider.classList.add('parvus__slider--is-dragging');
slider.style.willChange = 'transform';
lightboxOverlayOpacity = getComputedStyle(lightboxOverlay).getPropertyValue('opacity');
event.stopPropagation();
};

/**
Expand All @@ -1197,14 +1199,15 @@ function Parvus(userOptions) {
* @param {Event} event - The touchmove event object
*/
const touchmoveHandler = event => {
event.preventDefault();
event.stopPropagation();
const {
clientX,
clientY
} = event.changedTouches[0];
drag.endX = parseInt(clientX, 10);
drag.endY = parseInt(clientY, 10);
doSwipe();
event.preventDefault();
};

/**
Expand All @@ -1213,7 +1216,8 @@ function Parvus(userOptions) {
* This function is called when the touch interaction ends. It handles the necessary
* actions and logic related to the touchend event.
*/
const touchendHandler = () => {
const touchendHandler = event => {
event.stopPropagation();
const {
slider
} = GROUPS[activeGroup];
Expand Down
Loading

0 comments on commit 8e399e6

Please sign in to comment.