-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
29 lines (24 loc) · 1.11 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
document.addEventListener("DOMContentLoaded", function() {
// Seleciona todos os links da navegação
const links = document.querySelectorAll('nav ul li a');
// Adiciona um evento de clique para cada link
links.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault(); // Previne o comportamento padrão do link
// Obtém o ID da seção alvo a partir do href do link
const targetId = this.getAttribute('href').substring(1);
// Encontra a seção correspondente com base no ID
const targetSection = document.getElementById(targetId);
// Verifica se a seção existe
if (targetSection) {
// Calcula a posição da seção em relação ao topo da página
const offsetTop = targetSection.offsetTop;
// Executa a rolagem suave até a posição da seção
window.scrollTo({
top: offsetTop,
behavior: 'smooth'
});
}
});
});
});