-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
201 lines (172 loc) · 5.66 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
window.onload = () => {
// Para verificar o scrollY sem que o evento scroll ser aplicado
if (window.scrollY > 0) {
document.body.classList.add('scroll-on')
} else {
document.body.classList.remove('scroll-on')
}
adjustBanner()
}
window.onscroll = () => {
// Chama a função scrollOn toda vez que o scroll for usado
scrollOn()
}
window.addEventListener('resize', () => {
adjustBanner()
checkInnerWidth(window.innerWidth)
})
function backToHome() {
if (window.scrollY > 0) {
window.scrollTo(0, 0)
}
}
const closeMenu = document.querySelector('.close-menu')
closeMenu.addEventListener('click', () => {
closeMenu.classList.toggle('active')
document.body.classList.toggle('menu-expanded')
})
function scrollOn() {
if (window.scrollY > 0) {
document.body.classList.add('scroll-on')
} else {
document.body.classList.remove('scroll-on')
}
}
// Funcões para passar imagem dos sliders
function nextContentSlider(event) {
if (event.deltaY < 0) {
event.target.scrollBy(300, 0)
} else {
event.target.scrollBy(-300, 0)
}
}
const wrapper = document.querySelector('.wrapper')
function menuExpanded() {
if (!(wrapper.offsetWidth >= 1024)) {
// Para não ativar o menu expanded na versão desktop
document.body.classList.toggle('menu-expanded')
}
}
function nextElementSlider(element) {
slider.style.left = element.offsetLeft + 'px'
slider.style.width = element.offsetWidth + 'px'
}
// Adicionando evento para os sliders, passando as funções sliders
function checkInnerWidth(windowWidth) {
if (windowWidth < 1024) {
console.log('mobile')
//Vai desabilitar o scroll slider somente na versão mobile/tablet
container.addEventListener('mouseover', () => {
document.documentElement.style.overflow = 'hidden'
container.addEventListener('wheel', nextContentSlider)
//adicionando uma class no meu body, quando o mouse estiver sobre o slider
document.body.classList.add('slider-on')
})
container.addEventListener('mouseout', () => {
document.documentElement.style.overflow = 'auto'
document.body.classList.remove('slider-on')
})
containerAstronauts.addEventListener('mouseover', () => {
document.documentElement.style.overflow = 'hidden'
containerAstronauts.addEventListener('wheel', nextContentSlider)
})
containerAstronauts.addEventListener('mouseout', () => {
document.documentElement.style.overflow = 'auto'
})
} else {
console.log('desktop')
// Vai habilitar o scroll novamente na versão desktop
container.addEventListener('mouseover', () => {
document.documentElement.style.overflow = 'auto'
})
containerAstronauts.addEventListener('mouseover', () => {
document.documentElement.style.overflow = 'auto'
})
}
}
function adjustBanner() {
let valueSumHeight = 530
if (window.innerWidth >= 648) {
valueSumHeight = 500
} else if (window.innerWidth >= 461) {
valueSumHeight = 490
} else if (window.innerWidth >= 459) {
valueSumHeight = 480
} else if (window.innerWidth >= 456) {
valueSumHeight = 510
} else if (window.innerWidth >= 450) {
valueSumHeight = 530
} else if (window.innerWidth >= 374) {
valueSumHeight = 520
} else if (window.innerWidth >= 346) {
valueSumHeight = 550
} else if (window.innerWidth >= 331) {
valueSumHeight = 580
} else if (window.innerWidth >= 292) {
valueSumHeight = 550
} else if (window.innerWidth >= 268) {
valueSumHeight = 620
} else if (window.innerWidth >= 251) {
valueSumHeight = 620
} else if (window.innerWidth >= 249) {
valueSumHeight = 680
} else if (window.innerWidth >= 248) {
valueSumHeight = 680
} else {
valueSumHeight = 710
}
let homeSectionBottom =
homeSection.offsetHeight + homeSection.offsetTop + valueSumHeight + 'px'
document.documentElement.style.setProperty(
'--off-set-home-stats',
homeSectionBottom
)
getComputedStyle(document.documentElement).getPropertyValue(
'--off-set-home-stats'
)
}
//Adicionando fechamento do menu apos usar clicar em uma opção
const listas = document.querySelectorAll('.menu ul li a')
listas.forEach(element => {
element.addEventListener('click', menuExpanded)
})
// Declaraçõse das variaveis
const container = document.querySelector('.container')
const containerAstronauts = document.querySelector('.content-popular-week')
const openMenu = document.querySelector('.open-menu')
// Adicionando navSlider
const slider = document.createElement('div')
const contentNavigation = document.querySelector('.content-navigation')
const options = document.querySelectorAll('.options ul li')
slider.setAttribute('class', 'slider')
contentNavigation.append(slider)
options.forEach(element => {
element.addEventListener('mouseover', event => {
nextElementSlider(event.target)
})
})
const element = document.querySelector('body:not(#navigation)')
const navigation = document.querySelector('#navigation')
element.addEventListener('mouseout', () => {
slider.style.width = '0px'
})
// Adicionando svg na col-c
const colunaC = document.querySelector('.col-c')
const svg = document.createElement('img')
svg.setAttribute('class', 'logo-art')
svg.setAttribute('src', './assets/badge.svg')
svg.setAttribute('alt', 'badge nfts')
colunaC.append(svg)
ScrollReveal({
origin: 'top',
duration: 1000,
distance: '30px'
}).reveal(
` #home, .slider-image, .stats, .home-section, #popular-week, #best-artists, .artist, footer`
)
// Adicionando aninhamento do banner para dispositivos mobile
let value = getComputedStyle(document.documentElement).getPropertyValue(
'--off-set-home-stats'
)
const homeSection = document.querySelector('.home-section')
checkInnerWidth(window.innerWidth)