-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
133 lines (108 loc) · 4.11 KB
/
script.js
File metadata and controls
133 lines (108 loc) · 4.11 KB
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
// Aguarda o DOM carregar completamente
document.addEventListener('DOMContentLoaded', function() {
// ===== MODAIS =====
const modals = ['m1', 'm2', 'm3'];
let currentModal = null;
// Abrir modal ao clicar nos hotspots
document.querySelectorAll('.hotspot').forEach(h => {
h.addEventListener('click', function(e) {
const modalId = this.dataset.modal;
if (!modalId) return;
// Fecha todos
modals.forEach(id => {
document.getElementById(id).style.display = 'none';
});
// Abre o selecionado
document.getElementById(modalId).style.display = 'flex';
currentModal = modalId;
});
});
// Função para fechar todos
function closeAllModals() {
modals.forEach(id => {
const modal = document.getElementById(id);
if (modal) modal.style.display = 'none';
});
currentModal = null;
}
// Fechar com botão X
document.querySelectorAll('.close').forEach(btn => {
btn.addEventListener('click', closeAllModals);
});
// Fechar clicando no fundo (overlay)
document.querySelectorAll('.modal-overlay').forEach(overlay => {
overlay.addEventListener('click', function(e) {
if (e.target === this) closeAllModals();
});
});
// Navegação entre modais
function navigateModals(direction) {
if (!currentModal) return;
const idx = modals.indexOf(currentModal);
if (idx === -1) return;
let newIdx;
if (direction === 'next') {
newIdx = (idx + 1) % modals.length;
} else {
newIdx = (idx - 1 + modals.length) % modals.length;
}
// Fecha atual e abre novo
modals.forEach(id => {
document.getElementById(id).style.display = 'none';
});
document.getElementById(modals[newIdx]).style.display = 'flex';
currentModal = modals[newIdx];
}
// Botões next e prev
document.querySelectorAll('.next').forEach(btn => {
btn.addEventListener('click', function() {
navigateModals('next');
});
});
document.querySelectorAll('.prev').forEach(btn => {
btn.addEventListener('click', function() {
navigateModals('prev');
});
});
// Fechar com tecla ESC
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') closeAllModals();
});
// ===== MENU DE NAVEGAÇÃO LATERAL =====
const sections = document.querySelectorAll('section[id]');
const navContainer = document.getElementById('sectionNav');
// Cria as bolinhas
sections.forEach((section, index) => {
const dot = document.createElement('div');
dot.className = 'nav-dot';
dot.setAttribute('data-index', index);
// Adiciona título como tooltip (se existir)
if (section.dataset.title) {
dot.title = section.dataset.title;
}
// Scroll ao clicar
dot.addEventListener('click', function() {
section.scrollIntoView({ behavior: 'smooth' });
});
navContainer.appendChild(dot);
});
// Atualiza bolinha ativa durante o scroll
function updateActiveDot() {
const dots = document.querySelectorAll('.nav-dot');
if (!dots.length) return;
let activeIndex = 0;
let minDistance = Infinity;
sections.forEach((section, i) => {
const rect = section.getBoundingClientRect();
const distance = Math.abs(rect.top);
if (distance < minDistance) {
minDistance = distance;
activeIndex = i;
}
});
dots.forEach(d => d.classList.remove('active'));
if (dots[activeIndex]) dots[activeIndex].classList.add('active');
}
window.addEventListener('scroll', updateActiveDot);
updateActiveDot(); // Executa uma vez no início
}); // Fim do DOMContentLoaded