UNPKG

swipescroll

Version:

Touch & drag horizontal scroll for carousels on mobile, laptops and desktops

48 lines (43 loc) 1.46 kB
// src/core/carouselScroll.js function initCarouselScroll(container) { if (!container) return; function updateWidth() { console.log("Visible width:", container.clientWidth, "Total width:", container.scrollWidth); } updateWidth(); window.addEventListener("resize", updateWidth); var touchStartX = 0; var scrollLeft = 0; // Solo manejamos touch var handleTouchStart = function handleTouchStart(e) { touchStartX = e.touches[0].pageX; scrollLeft = container.scrollLeft; }; var handleTouchMove = function handleTouchMove(e) { var x = e.touches[0].pageX; var walk = (x - touchStartX) * 1.5; container.scrollLeft = scrollLeft - walk; e.preventDefault(); // evita scroll vertical del navegador }; container.addEventListener("touchstart", handleTouchStart, { passive: false }); container.addEventListener("touchmove", handleTouchMove, { passive: false }); return function () { window.removeEventListener("resize", updateWidth); container.removeEventListener("touchstart", handleTouchStart); container.removeEventListener("touchmove", handleTouchMove); }; } // index.js // ⚠️ Opcional: solo si NO usas UMD en el core // Si carouselScroll.js tiene UMD, esto NO debe estar aquí if (typeof window !== "undefined" && !window.DriftScroll) { window.DriftScroll = { initCarouselScroll: initCarouselScroll }; } export { initCarouselScroll }; //# sourceMappingURL=index.esm.js.map