-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
137 lines (113 loc) · 3.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
window.addEventListener('scroll', onScroll)
onScroll()
function onScroll() {
showNavOnScroll()
showBackToTopButtonOnScroll()
activateMenuAtCurrentSection(home)
activateMenuAtCurrentSection(services)
activateMenuAtCurrentSection(about)
activateMenuAtCurrentSection(contact)
activateMenuAtCurrentSection(deposition)
}
function activateMenuAtCurrentSection(section) {
const targetLine = scrollY + innerHeight / 2
// verificar se a seção passou da linha
// quais dados vou precisar?
const sectionTop = section.offsetTop
const sectionHeight = section.offsetHeight
const sectionTopReachOrPassedTargetline = targetLine >= sectionTop
// verificar se a base está abaixo da linha alvo
const sectionEndsAt = sectionTop + sectionHeight
const sectionEndPassedTargetline = sectionEndsAt <= targetLine
// limites da seção
const sectionBoundaries =
sectionTopReachOrPassedTargetline && !sectionEndPassedTargetline
const sectionId = section.getAttribute('id')
const menuElement = document.querySelector(`.menu a[href*=${sectionId}]`)
menuElement.classList.remove('active')
if (sectionBoundaries) {
menuElement.classList.add('active')
}
}
function showNavOnScroll() {
const navigation = document.querySelector('#navigation')
if (scrollY > 0) {
navigation.classList.add('scroll')
} else {
navigation.classList.remove('scroll')
}
}
function showBackToTopButtonOnScroll() {
if (scrollY > 550) {
backToTopButton.classList.add('show')
} else {
backToTopButton.classList.remove('show')
}
}
function openMenu() {
document.body.classList.add('menu-expanded')
}
function closeMenu() {
document.body.classList.remove('menu-expanded')
}
function cardSwap(event) {
const el = event.target
let parent = el.parentElement
while (!parent.classList.contains('button')) {
parent = parent.parentElement
}
const selectedbutton = document.querySelector(`#deposition .button.selected`)
selectedbutton.classList.remove('selected')
parent.classList.add('selected')
let index = parseInt(parent.dataset.index)
const transition = document.querySelectorAll('#deposition .transition')
transition.forEach(transition => [transition.classList.add('hidden')])
transition[index].classList.remove('hidden')
}
let curSlide = 0
const slides = document.querySelectorAll('.mobile')
// loop through slides and set each slides translateX property to index * 100%
slides.forEach((slide, indx) => {
slide.style.transform = `translateX(${indx * 100}%)`
})
// select next slide button
const nextSlide = document.querySelector('.vector.forward')
// add event listener and next slide functionality
nextSlide.addEventListener('click', function () {
curSlide++
slides.forEach((slide, indx) => {
slide.style.transform = `translateX(${35 * (indx - curSlide)}%)`
})
})
// select prev slide button
const prevSlide = document.querySelector('.vector.backward')
// add event listener and navigation functionality
prevSlide.addEventListener('click', function () {
// check if current slide is the first and reset current slide to last
if (curSlide === 0) {
curSlide = maxSlide
} else {
curSlide--
}
// move slide by 100%
slides.forEach((slide, indx) => {
slide.style.transform = `translateX(${35 * (indx - curSlide)}%)`
})
})
ScrollReveal({
origin: 'top',
distance: '30px',
duration: 700
}).reveal(`
#home,
#home img,
#home .stats,
#services,
#services header,
#services .card
#about,
#about header,
#about .content,
#deposition,
#deposition .cards,
#deposition .logos`)