-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
70 lines (59 loc) · 1.73 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
// JavaScript code for the header effects on scroll
window.addEventListener("scroll", function () {
var header = document.querySelector(".header");
header.classList.toggle("sticky", window.scrollY > 0);
});
// JavaScript code for the responsive navigation sidebar menu
var menuToggle = document.querySelector(".toggle");
var menu = document.querySelector(".menu");
var icons = document.querySelector(".icons");
menuToggle.addEventListener("click", function () {
menuToggle.classList.toggle("active");
menu.classList.toggle("active");
icons.classList.toggle("active");
});
// JavaScript code for the image slider
var slides = document.querySelectorAll(".slide");
var btns = document.querySelectorAll(".btn");
let currentSlide = 1;
// Javascript for image slider manual navigation
var manualNav = function (manual) {
slides.forEach((slide) => {
slide.classList.remove("active");
btns.forEach((btn) => {
btn.classList.remove("active");
});
});
slides[manual].classList.add("active");
btns[manual].classList.add("active");
};
btns.forEach((btn, i) => {
btn.addEventListener("click", () => {
manualNav(i);
currentSlide = i;
});
});
// Javascript for image slider autoplay navigation
var repeat = function (activeClass) {
let active = document.getElementsByClassName("active");
let i = 1;
var repeater = () => {
setTimeout(function () {
[...active].forEach((activeSlide) => {
activeSlide.classList.remove("active");
});
slides[i].classList.add("active");
btns[i].classList.add("active");
i++;
if (slides.length == i) {
i = 0;
}
if (i >= slides.length) {
return;
}
repeater();
}, 4000);
};
repeater();
};
repeat();