-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
114 lines (91 loc) · 3.97 KB
/
Copy pathscript.js
File metadata and controls
114 lines (91 loc) · 3.97 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
document.addEventListener('DOMContentLoaded', () => {
// --- 1. FUNCIONALIDAD DEL MENÚ DE HAMBURGUESA ---
const menuToggle = document.querySelector('.menu-toggle');
const navLinks = document.querySelector('.nav-links');
if (menuToggle && navLinks) {
menuToggle.addEventListener('click', () => {
navLinks.classList.toggle('active');
});
}
// ---------------------------------------------------------------- //
// --- 2. SCROLL SUAVE A SECCIONES ---
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetElement = document.querySelector(targetId);
if (targetElement) {
targetElement.scrollIntoView({
behavior: 'smooth'
});
// Opcional: Cierra el menú móvil después de hacer clic en un enlace
if (navLinks.classList.contains('active')) {
navLinks.classList.remove('active');
}
}
});
});
// ---------------------------------------------------------------- //
// --- 3. EFECTO DE SOMBRA EN EL HEADER AL SCROLL ---
const header = document.querySelector('.navbar');
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
header.classList.add('scrolled');
} else {
header.classList.remove('scrolled');
}
});
// ---------------------------------------------------------------- //
// --- 4. EFECTO DE ESCRITURA (TYPING EFFECT) ---
const textElement = document.getElementById('typing-text');
const textToType = "Welcome to our world";
let index = 0;
const typingSpeed = 100;
// Aseguramos que el elemento exista antes de intentar escribir
if (textElement) {
function typeWriter() {
if (index < textToType.length) {
textElement.textContent += textToType.charAt(index);
index++;
setTimeout(typeWriter, typingSpeed);
}
}
// Inicia
typeWriter();
textElement.classList.add('typing-cursor');
}
});
// --- 5. VALIDACIÓN DEL FORMULARIO ---
// Función para validar el formato del email (REGEX)
function isValidEmail(email) {
// Regex simple para verificar si el formato es parecido a "a@b.c"
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
// Función que se llama al enviar el formulario
window.validateForm = function() {
const name = document.getElementById('name').value.trim();
const email = document.getElementById('email').value.trim();
const message = document.getElementById('message').value.trim();
// 1. Validar campos vacíos
if (name === "" || email === "" || message === "") {
alert("Por favor, completa todos los campos.");
return false; // Previene el envío del formulario
}
// 2. Validar formato de email
if (!isValidEmail(email)) {
alert("Por favor, introduce una dirección de correo electrónico válida.");
return false; // Previene el envío del formulario
}
// Si todo es correcto:
alert("¡Mensaje enviado con éxito! Nos pondremos en contacto pronto.");
return true; // Permite el envío del formulario
};
// --- 6. EFECTO DE SEGUIMIENTO DE RATÓN (NEON CURSOR) ---
const neonCursor = document.getElementById('neon-cursor');
if (neonCursor && !('ontouchstart' in window || navigator.maxTouchPoints)) {
document.addEventListener('mousemove', (e) => {
// Actualiza la posicion
neonCursor.style.transform = `translate(${e.clientX}px, ${e.clientY}px)`;
});
}