-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
103 lines (87 loc) · 4.37 KB
/
Copy pathscript.js
File metadata and controls
103 lines (87 loc) · 4.37 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
document.addEventListener("DOMContentLoaded", () => {
// ===== IMPLEMENTACIÓN 1: SCROLL SUAVE PARA LINKS INTERNOS =====
// Intercepta clics en anclas (#seccion) y anima el desplazamiento
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener("click", (e) => {
e.preventDefault();
const target = document.querySelector(anchor.getAttribute("href"));
if (target) target.scrollIntoView({ behavior: "smooth" });
});
});
// ===== IMPLEMENTACIÓN 2: INTERSECTION OBSERVER (NAV ACTIVO + FADE-IN) =====
// Resalta el link del navbar correspondiente a la sección visible
const sections = document.querySelectorAll("header[id], section[id]");
const navLinks = document.querySelectorAll(".nav-links a");
const navObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
navLinks.forEach(link => link.classList.remove("active"));
const activeLink = document.querySelector(`.nav-links a[href="#${entry.target.id}"]`);
if (activeLink) activeLink.classList.add("active");
}
});
}, { threshold: 0.4 });
sections.forEach(section => navObserver.observe(section));
// Aplica clase 'visible' a las secciones cuando entran al viewport
const fadeEls = document.querySelectorAll(".fade-in");
const fadeObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add("visible");
}
});
}, { threshold: 0.15 });
fadeEls.forEach(el => fadeObserver.observe(el));
// ===== PLUS: FORMULARIO RÁPIDO (index.html) =====
// Prepara un mailto con los datos del formulario y abre el cliente de correo
const form = document.getElementById("contact-form");
if (form) {
form.addEventListener("submit", (e) => {
e.preventDefault();
const nombre = form.nombre.value.trim();
const email = form.email.value.trim();
const mensaje = form.mensaje.value.trim();
const subject = encodeURIComponent(`Mensaje de ${nombre}`);
const body = encodeURIComponent(`De: ${nombre}\nCorreo: ${email}\n\n${mensaje}`);
window.location.href = `mailto:Estbancolombia@gmail.com?subject=${subject}&body=${body}`;
form.reset();
});
}
// ===== PLUS: FORMULARIO COMPLETO CON VALIDACIÓN (contacto.html) =====
const formFull = document.getElementById("contact-form-full");
if (formFull) {
const errorDiv = document.getElementById("form-error");
const successDiv = document.getElementById("form-success");
formFull.addEventListener("submit", (e) => {
e.preventDefault();
errorDiv.hidden = true;
successDiv.hidden = true;
const nombre = formFull.nombre.value.trim();
const email = formFull.email.value.trim();
const mensaje = formFull.mensaje.value.trim();
// Verifica que los campos obligatorios estén completos
if (!nombre || !email || !mensaje) {
errorDiv.textContent = "Por favor completa todos los campos obligatorios (*).";
errorDiv.hidden = false;
return;
}
// Valida formato básico de correo electrónico
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
errorDiv.textContent = "Por favor ingresa un correo electrónico válido.";
errorDiv.hidden = false;
return;
}
const asunto = formFull.asunto.value.trim() || "Contacto desde portafolio";
const tipo = formFull.tipo.value || "General";
const subject = encodeURIComponent(`[${tipo}] ${asunto} — ${nombre}`);
const body = encodeURIComponent(
`Nombre: ${nombre}\nCorreo: ${email}\nAsunto: ${asunto}\nTipo: ${tipo}\n\nMensaje:\n${mensaje}`
);
window.location.href = `mailto:Estbancolombia@gmail.com?subject=${subject}&body=${body}`;
successDiv.textContent = "¡Mensaje preparado! Se abrirá tu cliente de correo.";
successDiv.hidden = false;
formFull.reset();
});
}
});