forked from B-o-r-g-e/sobupdated
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
82 lines (71 loc) · 1.85 KB
/
app.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
const phases=document.getElementsByClassName("phase1")
let phasePosition=0
const maxPhase= phases.length-1
const prevBtn=document.getElementById("prev")
const nextBtn=document.getElementById("next")
const switchBtns=document.getElementsByClassName("phase-switch")
const updateFunc=function(){
for(phase of phases){
phase.classList.remove("active")
}
for(switchBtn of switchBtns){
switchBtn.classList.remove("active-phase")
}
phases[phasePosition].classList.add("active")
switchBtns[phasePosition].classList.add("active-phase")
}
for (let i = 0; i < switchBtns.length; i++) {
switchBtns[i].addEventListener("click", function(){
phasePosition=i;
updateFunc();
})
}
const prevFunc=function(){
if (phasePosition < 1){
phasePosition=maxPhase
}
else{
phasePosition--
}
updateFunc()
}
const nextFunc=function(){
if (phasePosition === maxPhase){
phasePosition=0
}
else{
phasePosition++
}
updateFunc()
}
prevBtn.addEventListener("click", function(){
prevFunc();
} )
nextBtn.addEventListener("click",function(){
nextFunc();
})
//animated banner background
const backgrounds= document.getElementsByClassName("banner-img")
const bgLenght=backgrounds.length
let bannerPosition=0;
const updateImg= function(){
for(background of backgrounds){
background.classList.remove("banner-active");
}
backgrounds[bannerPosition].classList.add('banner-active')
}
const positionIncrement= function(){
if(bannerPosition===bgLenght-1){
bannerPosition=0
}
else if(bannerPosition<0){
bannerPosition=bgLenght-1
}
else{
bannerPosition++
}
}
setInterval( () => {
positionIncrement()
updateImg()
}, 3000);