Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated the pan issue #13

Open
wants to merge 1 commit into
base: with_navbar
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,39 @@ carousel.addEventListener("touchmove", dragging);

document.addEventListener("mouseup", dragStop);
carousel.addEventListener("touchend", dragStop);

const mapContainer = document.querySelector("#map"); // Replace with the correct map container selector

let isPanning = false;
let startX, startY, scrollLeft, scrollTop;

mapContainer.addEventListener("mousedown", (e) => {
isPanning = true;
startX = e.pageX - mapContainer.offsetLeft;
startY = e.pageY - mapContainer.offsetTop;
scrollLeft = mapContainer.scrollLeft;
scrollTop = mapContainer.scrollTop;
mapContainer.style.cursor = "grabbing";
});

mapContainer.addEventListener("mousemove", (e) => {
if (!isPanning) return;
e.preventDefault();
const x = e.pageX - mapContainer.offsetLeft;
const y = e.pageY - mapContainer.offsetTop;
const walkX = (x - startX); // Horizontal distance moved
const walkY = (y - startY); // Vertical distance moved
mapContainer.scrollLeft = scrollLeft - walkX;
mapContainer.scrollTop = scrollTop - walkY;
});

mapContainer.addEventListener("mouseup", () => {
isPanning = false;
mapContainer.style.cursor = "grab";
});

mapContainer.addEventListener("mouseleave", () => {
isPanning = false;
mapContainer.style.cursor = "grab";
});

Loading