Spaces:
Sleeping
Sleeping
File size: 1,087 Bytes
05dddec |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
function handleLeft() {
let slider = document.getElementById("eventSlider");
let event = document.getElementById("event");
slider.scrollLeft += event.offsetWidth + 20;
}
function handleRight() {
let slider = document.getElementById("eventSlider");
let event = document.getElementById("event");
slider.scrollLeft -= event.offsetWidth + 20;
}
// Mouse Drag Script
const slider = document.querySelector(".eventGrabSlider");
let isDown = false;
let startX;
let scrollLeft;
slider.addEventListener("mousedown", (e) => {
isDown = true;
// slider.classList.add('active');
startX = e.pageX - slider.offsetLeft;
scrollLeft = slider.scrollLeft;
});
slider.addEventListener("mouseleave", () => {
isDown = false;
slider.classList.remove("active");
});
slider.addEventListener("mouseup", () => {
isDown = false;
slider.classList.remove("active");
});
slider.addEventListener("mousemove", (e) => {
if (!isDown) return;
e.preventDefault();
const x = e.pageX - slider.offsetLeft;
const walk = x - startX; //scroll-fast
slider.scrollLeft = scrollLeft - walk;
console.log(walk);
});
|