-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
21 lines (19 loc) · 949 Bytes
/
Copy pathscript.js
File metadata and controls
21 lines (19 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// script.js - PÁGINA INICIAL (index.html)
document.addEventListener('DOMContentLoaded', () => {
// única funcionalidade que só existe na home é o scroll para a seção vegetariana.
const vegNavButton = document.getElementById('nav-veg-btn');
const vegetarianSection = document.getElementById('vegetarian-food');
const header = document.getElementById('main_header');
// verifica se os elementos existem antes de adicionar o evento
if (vegNavButton && vegetarianSection && header) {
vegNavButton.addEventListener('click', () => {
const headerHeight = header.offsetHeight;
const sectionPosition = vegetarianSection.getBoundingClientRect().top + window.scrollY;
const offsetPosition = sectionPosition - headerHeight;
window.scrollTo({
top: offsetPosition,
behavior: "smooth"
});
});
}
});