-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
91 lines (76 loc) · 2.28 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 useBtn = document.querySelector('#user-btn');
menu.addEventListener('click', function () {
let nev = document.querySelector(
".navbar");
nev.classList.toggle('active');
});
useBtn.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');
console.log(slider);
// scroll to right ??this one
function scrollRight() {
if (slider.scrollWidth - slider.clientWidth === (slider.scrollLeft).toFixed()) {
slider.scrollTo({
left: 0,
behavior: "smooth"
});
} else {
slider.scrollBy({
left: window.innerWidth,
behavior: 'smooth'
})
}
}
// scroll to left
function scrollLeft() {
slider.scrollBy({
left: -window.innerWidth,
behavior: 'smooth'
})
}
let timerId = setInterval(scrollRight,7000);
/*-------------reset timer to scrol right-------------- */
function resetTimer(){
clearInterval(timerId);
timerId = setInterval(scrollRight,7000);
}
/*---------------scroll event---------------- */
slider.addEventListener('click',function(ev){
if(ev.target === leftArrow){
scrollLeft();
resetTimer();
}
})
slider.addEventListener('click',function(ev){
if(ev.target === rightArrow){
scrollRight();
resetTimer();
}
})
/*--------------testimonial slider------------- */
let slides = document.querySelectorAll('.testimonial-item');
let index =0;
function nextSlider(){
slider[index].classList.remove('active');
index = (index+1) % slider.length;
slider[index].classList.add('active');
}
function preSlider(){
slider[index].classList.remove('active');
index = (index-1+slider.length) % slider.length;
slider[index].classList.add('active');
}