-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
91 lines (76 loc) · 2.32 KB
/
script.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
function initTabNav() {
const tabMenu = document.querySelectorAll('.js-tabmenu li');
const tabContent = document.querySelectorAll('.js-tabcontent section');
if(tabMenu.length && tabContent.length) {
tabContent[0].classList.add('ativo');
function activeTab(index) {
tabContent.forEach((section) => {
section.classList.remove('ativo');
});
tabContent[index].classList.add('ativo');
}
tabMenu.forEach((itemMenu, index) => {
itemMenu.addEventListener('click', () => {
activeTab(index);
});
});
}
}
initTabNav();
function initAccordion() {
const accordionList = document.querySelectorAll('.js-accordion dt');
const activeClass = 'ativo';
if(accordionList.length) {
accordionList[0].classList.add(activeClass);
accordionList[0].nextElementSibling.classList.add(activeClass);
function activeAccordion() {
this.classList.toggle(activeClass);
this.nextElementSibling.classList.toggle(activeClass);
}
accordionList.forEach((item) => {
item.addEventListener('click', activeAccordion);
});
}
}
initAccordion();
function initScrollSuave() {
const linksInternos = document.querySelectorAll('.js-menu a[href^="#"]');
function scrollToSection(event) {
event.preventDefault();
const href = event.currentTarget.getAttribute('href');
const section = document.querySelector(href);
section.scrollIntoView({
behavior: 'smooth',
block: 'start',
});
// forma alternativa
// const topo = section.offsetTop;
// window.scrollTo({
// top: topo,
// behavior: 'smooth',
// });
}
linksInternos.forEach((link) => {
link.addEventListener('click', scrollToSection);
});
}
initScrollSuave();
function initAnimacaoScroll() {
const sections = document.querySelectorAll('.js-scroll');
if(sections.length) {
const windowMetade = window.innerHeight * 0.6;
function animaScroll() {
sections.forEach((section) => {
const sectionTop = section.getBoundingClientRect().top;
const isSectionVisible = (sectionTop - windowMetade) < 0;
if(isSectionVisible)
section.classList.add('ativo');
else
section.classList.remove('ativo');
})
}
animaScroll();
window.addEventListener('scroll', animaScroll);
}
}
initAnimacaoScroll();