-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
91 lines (72 loc) · 2.29 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const header = document.querySelector('header');
function fixedNavbar(){
header.classList.toggle('scroll', window.pageYOffset > 0)
}
fixedNavbar();
window.addEventListener('scroll', fixedNavbar);
let menu = document.querySelector('#menu-btn');
let userBtn = document.querySelector('#user-btn');
menu.addEventListener('click', function(){
let nav = document.querySelector('.navbar');
nav.classList.toggle('active');
})
userBtn.addEventListener('click',function(){
let userBox = document.querySelector('.user-box');
userBox.classList.toggle('active');
})
/* home page slider */
"use strict"
const leftArrow = document.querySelector('.left-arrow .bxs-left-arrow'),
rightArrow = document.querySelector('.right-arrow .bxs-right-arrow'),
slider = document.querySelector('.slider');
function scrollRight(){
if (slider.scrollWidth - slider.clientWidth === slider.scrollLeft){
slider.scrollBy({
left:0,
behavior: "smooth"
})
}else{
slider.scrollBy({
left: window.innerWidth,
behavior: "smooth"
})
}
}
function scrollLeft(){
slider.scrollBy({
left:0- window.innerWidth,
behavior: "smooth"
})
}
let timerId = setInterval(scrollRight, 7000);
function resertTimer(){
clearInterval(timerId);
timerId = setInterval(scrollRight, 7000);
}
slider.addEventListener('click',function(ev){
if(ev.target === rightArrow){
scrollRight();
resertTimer();
}
});
slider.addEventListener('click',function(ev){
if(ev.target === leftArrow){
scrollLeft();
resertTimer();
}
});
/*---- testimonial ----*/
function nextSlide(){
let slides = document.querySelectorAll('.testimonial-item');
let index = Array.from(slides).indexOf(document.querySelector('.testimonial-item.active'));
slides[index].classList.remove('active');
index = (index + 1) % slides.length;
slides[index].classList.add('active');
}
function prevSlide(){
let slides = document.querySelectorAll('.testimonial-item');
let index = Array.from(slides).indexOf(document.querySelector('.testimonial-item.active'));
slides[index].classList.remove('active');
index = (index - 1 + slides.length) % slides.length;
slides[index].classList.add('active');
}