-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
55 lines (50 loc) · 1.54 KB
/
main.js
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const scrollers = document.querySelectorAll(".scroller");
// If a user hasn't opted in for recuded motion, then we add the animation
if (!window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
addAnimation();
}
function addAnimation() {
scrollers.forEach((scroller) => {
// add data-animated="true" to every `.scroller` on the page
scroller.setAttribute("data-animated", true);
// Make an array from the elements within `.scroller-inner`
const scrollerInner = scroller.querySelector(".scroller__inner");
const scrollerContent = Array.from(scrollerInner.children);
// For each item in the array, clone it
// add aria-hidden to it
// add it into the `.scroller-inner`
scrollerContent.forEach((item) => {
const duplicatedItem = item.cloneNode(true);
duplicatedItem.setAttribute("aria-hidden", true);
scrollerInner.appendChild(duplicatedItem);
});
});
}
document.addEventListener("DOMContentLoaded", () => {
const swiper = new Swiper(".swiper", {
// Swiper options
slidesPerView: 1,
spaceBetween: 5,
loop: true, // Loop through the slides infinitely
autoplay: {
delay: 1000, // 3 seconds between transitions
disableOnInteraction: false,
},
pagination: {
el: ".swiper-pagination",
clickable: true,
},
breakpoints: {
// Responsive breakpoints
768: {
slidesPerView: 2,
spaceBetween: 10,
},
1024: {
slidesPerView: 3,
spaceBetween: 0,
},
},
});
console.log(swiper);
});