Skip to content

Commit

Permalink
add passive event listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasr22 committed Nov 20, 2024
1 parent 51ae8e2 commit 7befc77
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions scripts/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ function initComparisons() {
slider.style.top = (h / 2) - (slider.offsetHeight / 2) + "px";
slider.style.left = (w / 2) + "px";

slider.addEventListener("mousedown", slideReady);
window.addEventListener("mouseup", slideFinish);
slider.addEventListener("touchstart", slideReady);
window.addEventListener("touchend", slideFinish);
slider.addEventListener("mousedown", slideReady, {passive: true});
window.addEventListener("mouseup", slideFinish, {passive: true});
slider.addEventListener("touchstart", slideReady, {passive: true});
window.addEventListener("touchend", slideFinish, {passive: true});

function slideReady(e) {
e.preventDefault();
clicked = true;

window.addEventListener("mousemove", slideMove);
window.addEventListener("touchmove", slideMove);
window.addEventListener("mousemove", slideMove, {passive: true});
window.addEventListener("touchmove", slideMove, {passive: true});
}

function slideFinish() {
Expand Down

0 comments on commit 7befc77

Please sign in to comment.