-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
43 lines (36 loc) · 1.22 KB
/
app.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
/* label the images, just for convenience, to visually track them */
/** This can be omitted! */
let i = 1;
for (let li of carousel.querySelectorAll("li")) {
li.style.position = "relative";
li.insertAdjacentHTML(
"beforeend",
`<span style="position:absolute;left:0;top:0">${i}</span>`
);
i++;
}
/* configuration */
let width = 130; // image width
let count = 3; // visible images count
let list = carousel.querySelector("ul");
let listElems = carousel.querySelectorAll("li");
let position = 0; // ribbon scroll position
carousel.querySelector(".prev").onclick = function () {
// shift left
position += width * count;
// can't move to the left too much, end of images
position = Math.min(position, 0);
list.style.marginLeft = position + "px";
};
carousel.querySelector(".next").onclick = function () {
// shift right
position -= width * count;
// can only shift the ribbbon for (total ribbon length - visible count) images
position = Math.max(position, -width * (listElems.length - count));
list.style.marginLeft = position + "px";
};
let menuElem = document.getElementById("sweeties");
let titleElem = menuElem.querySelector(".title");
titleElem.onclick = function () {
menuElem.classList.toggle("open");
};