-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
67 lines (60 loc) · 2.4 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
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
document.addEventListener('DOMContentLoaded', function() {
var circle = document.getElementById('circle');
var navHeight = document.querySelector('.contenedor-header').offsetHeight;
var menuToggle = document.querySelector('.menu-toggle');
var menu = document.querySelector('#nav ul');
function toggleMenu() {
menu.classList.toggle('active');
}
// Manejador para el botón de menú hamburguesa
menuToggle.addEventListener('click', toggleMenu);
document.querySelectorAll('a').forEach(function(link) {
link.addEventListener('mouseenter', function() {
circle.classList.add('hover');
});
link.addEventListener('mouseleave', function() {
circle.classList.remove('hover');
});
link.addEventListener('click', function(e) {
var href = this.getAttribute('href');
if (href.startsWith('#')) {
e.preventDefault();
var targetElement = document.querySelector(href);
if (targetElement) {
var scrollToPosition = targetElement.offsetTop - navHeight;
window.scrollTo({ top: scrollToPosition, behavior: 'smooth' });
}
}
});
});
document.addEventListener('mousemove', function(e) {
circle.style.left = e.clientX + 'px';
circle.style.top = e.clientY + 'px';
});
const form = document.querySelector(".formcontato__form");
if (form) {
form.addEventListener("submit", validateForm);
form.querySelectorAll("input[type='text'], input[type='email'], textarea").forEach(input => {
input.addEventListener('input', function() {
if (this.value.trim()) {
this.classList.remove('invalid-input');
}
});
});
}
});
function validateForm(event) {
const inputs = this.querySelectorAll("input[type='text'], input[type='email'], textarea");
let valid = true;
inputs.forEach(input => {
if (!input.value.trim()) {
input.classList.add('invalid-input');
valid = false;
} else {
input.classList.remove('invalid-input');
}
});
if (!valid) {
event.preventDefault(); // Detiene el envío del formulario si hay campos no completados
}
}