-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
37 lines (32 loc) · 893 Bytes
/
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
const slider = document.querySelector(".container");
let isDown = false;
let startX;
let scrollLeft;
for (let i = 1; i <= 31; i++) {
let div = document.createElement("div");
div.classList.add("slide");
div.innerHTML = `
<img src="/SwipperJs/images/1 (${i}).jpg" />
`;
slider.appendChild(div);
}
slider.addEventListener("mousedown", (e) => {
isDown = true;
slider.style.cursor = "grabbing";
startX = e.pageX - slider.offsetLeft;
scrollLeft = slider.scrollLeft;
});
slider.addEventListener("mouseleave", () => {
isDown = false;
});
slider.addEventListener("mouseup", () => {
isDown = false;
slider.style.cursor = "pointer";
});
slider.addEventListener("mousemove", (e) => {
if (!isDown) return; // stop the fn from running
e.preventDefault();
const x = e.pageX - slider.offsetLeft;
const walk = x - startX;
slider.scrollLeft = scrollLeft - walk;
});