-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
70 lines (56 loc) · 1.54 KB
/
script.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
let navbar = document.getElementById('navbar');
const toggle = () =>{
if (navbar.style.display == 'none') {
navbar.style.display = 'block';
navbar.style.textAlign = 'left';
} else {
navbar.style.display = 'none';
}
}
function carousel() {
let carouselSlider = document.querySelector('.carousel-slider');
let list = document.querySelector('.carousel-list');
let item = document.querySelector('.carousel-item');
let list2;
const speed = 1;
const width = list.offsetWidth;
let x = 0;
let x2 = width;
function clone() {
list2 = list.cloneNode(true);
carouselSlider.appendChild(list2);
list2.style.left = `${width}px`;
}
function moveFirst() {
x -= speed;
if (width >= Math.abs(x)) {
list.style.left = `${x}px`;
} else {
x = width;
}
}
function moveSecond() {
x2 -= speed;
if (list.offsetWidth >= Math.abs(x2)) {
list2.style.left = `${x2}px`;
} else {
x2 = width;
}
}
function hover() {
clearInterval(a);
clearInterval(b);
}
function unhover() {
clearInterval(a);
clearInterval(b);
a = setInterval(moveFirst, 10);
b = setInterval(moveSecond, 10);
}
clone();
let a = setInterval(moveFirst, 10);
let b = setInterval(moveSecond, 10);
carouselSlider.addEventListener('mouseenter', hover);
carouselSlider.addEventListener('mouseleave', unhover);
}
carousel();