-
Notifications
You must be signed in to change notification settings - Fork 0
/
movieslider.js
43 lines (39 loc) · 1.27 KB
/
movieslider.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
const slider = document.querySelector(".movieslide");
const form = document.querySelector(".form");
let mouseDownAt = 0;
let left = 0;
slider.onmousedown = (e) => {
mouseDownAt = e.clientX;
console.log(mouseDownAt);
};
slider.onmouseup = () => {
mouseDownAt = 0;
slider.style.userSelect = 'unset';
slider.style.cursor = 'unset';
form.style.pointerEvents = 'unset';
form.classList.remove('left');
form.classList.remove('right');
}
slider.onmousemove = e => {
if(mouseDownAt == 0) return;
slider.style.userSelect = 'none';
slider.style.cursor = 'grab';
form.style.pointerEvents = 'none';
if(e.clientX > mouseDownAt){
form.classList.add('left');
form.classList.remove('right');
}else if(e.clientX < mouseDownAt){
form.classList.remove('left');
form.classList.add('right');
}
// increase or decrease the speed
//by changing the value of 'speed'
let speed = 3;
let leftTemporary = left + ((e.clientX - mouseDownAt) / speed);
let leftLimit = form.offsetWidth - slider.offsetWidth / 2;
if(leftTemporary < 0 && Math.abs(leftTemporary) < leftLimit){
form.style.setProperty('--left', left + 'px');
left = leftTemporary;
mouseDownAt = e.clientX;
}
}