File size: 1,237 Bytes
187ef74 | 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 | // Destination carousel arrows: scroll the strip one viewport per click and
// reflect scroll position in the disabled states. The strip itself is an
// ordinary horizontally scrollable list without JS.
(function () {
"use strict";
document.querySelectorAll("[data-carousel-arrows]").forEach(function (bar) {
var name = bar.getAttribute("data-carousel-arrows");
var strip = document.querySelector('[data-carousel="' + name + '"]');
if (!strip) return;
bar.hidden = false;
var prev = bar.querySelector("[data-carousel-prev]");
var next = bar.querySelector("[data-carousel-next]");
function step() {
return Math.max(strip.clientWidth * 0.8, 240);
}
function sync() {
var max = strip.scrollWidth - strip.clientWidth - 4;
prev.disabled = strip.scrollLeft <= 4;
next.disabled = strip.scrollLeft >= max;
}
prev.addEventListener("click", function () {
strip.scrollBy({ left: -step(), behavior: "smooth" });
});
next.addEventListener("click", function () {
strip.scrollBy({ left: step(), behavior: "smooth" });
});
strip.addEventListener("scroll", sync, { passive: true });
window.addEventListener("resize", sync);
sync();
});
})();
|