-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
32 lines (27 loc) · 867 Bytes
/
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
let $slider = document.getElementsByClassName('slider')[0];
let slideIndex = 1;
let $btn = document.getElementById('sidebar-open-btn');
let $close_btn = document.getElementById('sidebar-close-btn');
showSlide(slideIndex);
function changeSlide(n) {
showSlide(slideIndex += n);
}
function showSlide(n) {
let i;
const slides = document.getElementsByClassName("slide");
if (n > slides.length) {
slideIndex = 1;
}
if (n < 1) {
slideIndex = slides.length;
}
$slider.scrollLeft = slides[slideIndex - 1].offsetLeft;
}
$btn.addEventListener('click', function() {
let sidebar = document.getElementById('sidebar');
sidebar.classList.toggle('sidebar-active');
});
$close_btn.addEventListener('click', function() {
let sidebar = document.getElementById('sidebar');
sidebar.classList.toggle('sidebar-active');
});