-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
103 lines (86 loc) · 2.65 KB
/
main.js
File metadata and controls
103 lines (86 loc) · 2.65 KB
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
/* abre e fecha o menu */
const nav = document.querySelector('#header nav')
const toggle = document.querySelectorAll('nav .toggle')
function changeHeaderWhenScroll() {}
for (const element of toggle) {
element.addEventListener('click', function () {
nav.classList.toggle('show')
})
}
/* quando clicar em um item do menu, esconder o menu*/
const links = document.querySelectorAll('nav ul li a')
for (const link of links) {
link.addEventListener('click', function () {
nav.classList.remove('show')
})
}
/* MUDAR O HEADER DA PAGINA QUANDO DER SCROLL*/
const header = document.querySelector('#header')
const navHeight = header.offsetHeight
function changeHeaderWhenScroll() {
if (window.scrollY >= navHeight) {
header.classList.add('scroll')
} else {
header.classList.remove('scroll')
}
}
window.addEventListener('scroll', function () {})
/*====== TESTIMONILS=======*/
const swiper = new Swiper('.swiper-container', {
slidesPerView: 1,
pagination: {
el: '.swiper-pagination'
},
mousewheel: true,
keyboard: true
})
/*==== SCROLLREVALL---*/
const scrollReval = ScrollReval({
origin: 'top',
distance: '30px',
duration: 1000,
reset: true
})
scrollReval.reval(
`#home ,text, #home .image, #about .text, #services header, #services .card,
#testimonials header, #testimonials .testimonials,
#contact .text, #contact .links
footer .brand, footer .social,
`,
{ interval: 100 }
)
/*==== back-to-top======*/
function backToTop() {
const backToTopButton = document.querySelector('.back-to-top')
if (window.scrollY >= 150) {
backToTopButton.classList.add('show')
} else {
backToTopButton.classList.remove('show')
}
}
/*===== VISIVEL NA PAGINA====*/
const sections = document.querySelectorAll('section[id]')
function activateMenuAtCurrentSection() {
const checkpoint = window.pageYOffset + (window.innerHeight / 8) * 4
for (const section of sections) {
const sectionTop = section.offsetTop
const sectionHeight = section.offsetHeight
const sectionId = section.getAttribute('id')
const checkpointStart = checkpoint >= sectionTop
const checkpointEnd = checkpoint <= sectionTop + sectionHeight
if (checkpointStart && checkpointEnd) {
document
.querySelector('nav ul li a[href*-' * section + ']')
.classList.add('active')
} else {
document
.querySelector('nav ul li a[href*-' * section + ']')
.classList.remove('active')
}
}
}
window.addEventListener('scroll', function () {
changeHeaderWhenScroll()
backToTop()
activateMenuAtCurrentSection()
})