-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
76 lines (61 loc) · 2.12 KB
/
Copy pathscript.js
File metadata and controls
76 lines (61 loc) · 2.12 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
// Close navbar on mobile
$(document).on("click", ".nav-link", function () {
$(".navbar-collapse").collapse("hide");
});
// Auto update the year (for the footer)
document.getElementById("year").textContent = new Date().getFullYear();
// Validate the contact form
$("#submitBtn").on("click", function () {
let isValid = true;
const name = $("#contactName").val().trim();
const email = $("#contactEmail").val().trim();
const message = $("#contactMessage").val().trim();
$("#contactName, #contactEmail, #contactMessage").removeClass("is-invalid");
$("#nameError, #emailError, #messageError").text("");
$("#form-success, #form-error").addClass("d-none");
if (name === "") {
$("#contactName").addClass("is-invalid");
$("#nameError").text("Please enter your name.");
isValid = false;
}
if (email === "") {
$("#contactEmail").addClass("is-invalid");
$("#emailError").text("Please enter your email.");
isValid = false;
} else if (!isValidEmail(email)) {
$("#contactEmail").addClass("is-invalid");
$("#emailError").text("Please enter a valid email address.");
isValid = false;
}
if (message === "") {
$("#contactMessage").addClass("is-invalid");
$("#messageError").text("Please enter a message.");
isValid = false;
}
if (isValid) {
$("#form-success").removeClass("d-none");
$("#contactName").val("");
$("#contactEmail").val("");
$("#contactSubject").val("");
$("#contactMessage").val("");
} else {
$("#form-error").removeClass("d-none");
}
});
// helper function to validate email
function isValidEmail(email) {
const pattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return pattern.test(email);
}
// Hero background slideshow
const heroImages = ["img/IMG_5053.jpg", "img/IMG_5466.jpg", "img/IMG_7904.jpg"];
let currentIndex = 0;
const heroSection = document.getElementById("home");
function changeBackground() {
heroSection.style.backgroundImage = `url('${heroImages[currentIndex]}')`;
currentIndex = (currentIndex + 1) % heroImages.length;
}
// Set first image immediately
changeBackground();
// Change every 5 seconds
setInterval(changeBackground, 5000);