-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinteraction.js
55 lines (44 loc) · 1.38 KB
/
interaction.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
import Carousel from "./vendor/carousel/carousel.js";
import Player from "./vendor/carousel/player.js";
//Carousel
customElements.define("tarugo-carousel", Carousel);
document.querySelectorAll("tarugo-carousel").forEach((carousel) => {
const player = new Player(carousel);
player.play();
const next = carousel.parentElement.querySelector(".js-carousel-next");
const prev = carousel.parentElement.querySelector(".js-carousel-prev");
next.addEventListener("click", (e) => {
player.stop();
carousel.next();
});
prev.addEventListener("click", (e) => {
player.stop();
carousel.prev();
});
//Disable buttons
let isScrolling;
carousel.addEventListener(
"scroll",
(event) => {
clearTimeout(isScrolling);
isScrolling = setTimeout(showHideButtons, 100);
},
false,
);
function showHideButtons() {
prev.disabled = carousel.scrollFromLeft < 5;
next.disabled = carousel.scrollFromRight < 5;
}
showHideButtons();
});
//Progress bar
document.querySelectorAll("#progress").forEach((element) => {
const start = new Date(2020, 0, 1);
const now = new Date();
const end = new Date(2020, 9, 22);
const total = Math.abs(start - end);
const progress = Math.abs(start - now);
const percentage = Math.round(progress / total * 100) + "%";
element.innerText = percentage;
element.style.setProperty("--progress", percentage);
});