-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
134 lines (116 loc) · 3.9 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
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
function funcionamento() {
const aberto = document.querySelector('.entrada__aberto-fechado')
setInterval(horarioFuncionamento, 1000)
function horarioFuncionamento() {
const date = new Date()
const d = date.getDay()
const hUtc = date.getUTCHours()
const horaAgora = hUtc - 3
if (horaAgora >= 8) {
if ((d == 6 || d == 0) && horaAgora < 16) {
styleAberto('Aberto agora', 'aberto')
}
else if ((d !== 6 && d !== 0) && horaAgora < 21) {
styleAberto('Aberto agora', 'aberto')
}
else {
styleAberto('Fechado agora', 'fechado')
}
} else {
styleAberto('Fechado agora', 'fechado')
}
}
function styleAberto(txt, dataType) {
aberto.textContent = txt;
aberto.dataset.open = dataType;
}
horarioFuncionamento()
}
funcionamento()
const headerMenu = document.querySelector('.header__btn-menu')
const nav = document.querySelector('.header__nav')
function openMenu() {
headerMenu.classList.toggle('ativo');
nav.classList.toggle('ativo')
}
function closeMenu() {
headerMenu.classList.remove('ativo');
nav.classList.remove('ativo')
}
headerMenu.addEventListener('click', openMenu)
window.addEventListener('scroll', closeMenu)
/* animaçao ao scroll */
const animaElements = document.querySelectorAll('[data-anima]')
function animateElements() {
const DISTANCE_WINDOW_TOP = window.pageYOffset + window.innerHeight * 4 / 5;
animaElements.forEach(element => {
const DISTANCE_ELEMENT_TOP = element.getBoundingClientRect().top + window.pageYOffset;
const delay = element.dataset.delay || 0;
if (DISTANCE_WINDOW_TOP > DISTANCE_ELEMENT_TOP) {
setTimeout(() => {
element.classList.add('animated')
}, delay);
} else if (DISTANCE_WINDOW_TOP < DISTANCE_ELEMENT_TOP + element.offsetHeight) {
element.classList.remove('animated')
}
})
}
animateElements()
window.addEventListener('scroll', animateElements)
/* Slide */
const containerSlide = document.querySelector('.profissionais__lista')
const btnProx = document.querySelector('.btn-prox')
const btnAnt = document.querySelector('.btn-ant')
let itemsPerSlide = 4;
let slideIndex = 0;
function disableOrEnableButton() {
btnAnt.classList.remove('disabled');
btnProx.classList.remove('disabled');
if (slideIndex === 0) {
btnAnt.classList.add('disabled')
} else if (slideIndex === containerSlide.children.length - itemsPerSlide) {
btnProx.classList.add('disabled')
}
}
function moveSlide(width) {
containerSlide.style.transform = `translateX(-${width * slideIndex}px)`;
}
function getMeasuresSlide() {
const slideItem = document.querySelectorAll('.profissionais__lista li')[1];
const slideItemWidth = slideItem.getBoundingClientRect().width;
const slideItemMargin = parseFloat(getComputedStyle(slideItem).marginLeft)
const slideDragWidth = slideItemWidth + slideItemMargin;
disableOrEnableButton()
moveSlide(slideDragWidth)
}
function changeSlidesPerPage() {
if (window.innerWidth >= 690) {
itemsPerSlide = 4
}
if (window.innerWidth < 690) {
itemsPerSlide = 3
}
if (window.innerWidth < 480) {
itemsPerSlide = 2
}
if (window.innerWidth < 400) {
itemsPerSlide = 1
}
slideIndex = 0;
disableOrEnableButton()
moveSlide(0);
}
changeSlidesPerPage()
btnProx.addEventListener('click', (e) => {
const btnDisabled = e.currentTarget.classList.contains('disabled');
if (btnDisabled) return;
++slideIndex;
getMeasuresSlide()
})
btnAnt.addEventListener('click', (e) => {
const btnDisabled = e.currentTarget.classList.contains('disabled');
if (btnDisabled) return;
--slideIndex;
getMeasuresSlide()
})
window.addEventListener('resize', changeSlidesPerPage)