-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
127 lines (108 loc) · 4.82 KB
/
main.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*=============== CHANGE BACKGROUND HEADER ===============*/
function scrollHeder() {
const header = document.getElementById('header')
//when the scroll is grater than 50 viewport height, add the
if(this.scrollY >= 50) header.classList.add('scroll-hrader');else header.classList.remove('scroll-hrader') ;
}
window.addEventListener('scroll',scrollHeder);
/*=============== SWIPER POPULAR ===============*/
var swiperPopular = new Swiper(".popular__container", {
spaceBetween: 32,
grabCursor: true,
centeredSlides: true,
slidesPerView: 'auto',
loop: true,
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev",
},
});
/*=============== VALUE ACCORDION ===============*/
const accordionItems = document.querySelectorAll('.value__accordion-item')
accordionItems.forEach((item) =>{
const accordionHeader = item.querySelector('.value__accordion-header')
accordionHeader.addEventListener('click',()=>{
const openItem = document.querySelector('.accordion-open')
toggleItem(item)
if(openItem && openItem !== item){
toggleItem(openItem)
}
})
})
const toggleItem = (item) =>{
const accordionContent = item.querySelector('.value__accordion-content')
if(item.classList.contains('accordion-open')){
accordionContent.removeAttribute('style')
item.classList.remove('accordion-open')
}else{
accordionContent.style.height =accordionContent.scrollHeight + 'px'
item.classList.add('accordion-open')
}
}
/*=============== SCROLL SECTIONS ACTIVE LINK ===============*/
const sections = document.querySelectorAll('section[id]')
function scrollActive() {
const scrollY = window.pageYOffset
sections.forEach(current =>{
const sectionHeight = current.offsetHeight,
sectionTop = current.offsetTop - 58,
sectionId = current.getAttribute('id')
if(scrollY > sectionTop && scrollY <= sectionTop + sectionHeight){
document.querySelector('.nav__menu a[href*=' + sectionId + ']').classList.add('active-link')
}else{
document.querySelector('.nav__menu a[href*=' + sectionId + ']').classList.remove('active-link')
}
})
}
window.addEventListener('scroll',scrollActive);
/*=============== SHOW SCROLL UP ===============*/
function scrollUp(){
const scrollUp = document.getElementById('scroll-up');
//when the scroll is higher then 350 viewport height , add the show-scroll class to the a tag with the scrollUp class
if(this.scrollY >= 350){
scrollUp.classList.add('show-scroll')}else{
scrollUp.classList.remove('show-scroll')
}
}
window.addEventListener('scroll',scrollUp)
/*=============== DARK LIGHT THEME ===============*/
const themeButton = document.getElementById('theme-button')
const darkTheme = 'dark-theme'
const iconTheme ='bx-sun'
//previously selected topic (if user selected)
const selectedTheme = localStorage.getItem('selected-theme')
const selectedIcon = localStorage.getItem('selected-icon')
//we obtain the current theme that the interface has by validating the dark-theme class
const getCurrentTheme = () => document.body.classList.contains(darkTheme) ? 'dark' : 'light'
const getCurrentIcon = () => themeButton.body.classList.contains(iconTheme) ? 'bx bx-moon' : 'bx bx-sun'
// we validate if the user previously chose a topic
if(selectedTheme){
// If the validation is fulfilled, we ask what the issue was to know if we activated or deactivated the dark
document.body.classList[selectedTheme === 'dark' ? 'add' : 'remove'](darkTheme)
themeButton.classList[selectedIcon === 'bx bx-moon' ? 'add' : 'remove'](iconTheme)
}
// Activate / deactivate the theme manually with the button
themeButton.addEventListener('click', () => {
// Add or remove the dark / icon theme
document.body.classList.toggle(darkTheme)
themeButton.classList.toggle(iconTheme)
// We save the theme and the current icon that the user chose
localStorage.setItem('selected-theme', getCurrentTheme())
localStorage.setItem('selected-icon', getCurrentIcon())
})
/*=============== SCROLL REVEAL ANIMATION ===============*/
const sr = ScrollReveal({
origin: 'top',
distance:'60px',
duration: 2500,
delay :400,
reset:true
})
sr.reveal(`.home__title, .popular__container, .subscribe__container, .footer__container`)
sr.reveal(`.home__description, .footer__info`,{delay:500})
sr.reveal(`.home__search`,{delay:600})
sr.reveal(`.home__value`,{delay:700})
sr.reveal(`.home__images`,{delay:800, origin:'bottom'})
sr.reveal(`.logos__img`,{interval:100})
sr.reveal(`.value__images, .contact__content`,{origin:'left'})
sr.reveal(`.value__content, .contact__images`,{origin:'right'})