File size: 1,007 Bytes
6a65890 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | /* Horizontal carousels. The accordions work without script (each toggle is a real
link the server renders), so this file only adds the arrow scrolling. */
(function () {
function step(track) {
var card = track.querySelector('li');
if (!card) return 300;
var styles = window.getComputedStyle(track);
var gap = parseFloat(styles.columnGap || styles.gap || '0') || 0;
return card.getBoundingClientRect().width + gap;
}
function bind(button, delta) {
var name = button.getAttribute('data-carousel-prev') || button.getAttribute('data-carousel-next');
var track = document.querySelector('[data-carousel="' + name + '"]');
if (!track) return;
button.addEventListener('click', function () {
track.scrollBy({ left: delta * step(track) * 2, behavior: 'smooth' });
});
}
document.querySelectorAll('[data-carousel-prev]').forEach(function (b) { bind(b, -1); });
document.querySelectorAll('[data-carousel-next]').forEach(function (b) { bind(b, 1); });
})();
|