willowmecreationsV2/script.js
2024-08-09 01:21:29 -04:00

78 lines
2.4 KiB
JavaScript

// Carousel Functionality
let currentIndex = 0;
let slides = document.getElementsByClassName("carousel-item");
let totalSlides = slides.length;
function showSlides() {
for (let i = 0; i < totalSlides; i++) {
slides[i].classList.remove("active");
}
currentIndex++;
if (currentIndex >= totalSlides) {
currentIndex = 0;
}
slides[currentIndex].classList.add("active");
setTimeout(showSlides, 3000); // Change image every 3 seconds
}
function moveSlides(n) {
currentIndex += n;
if (currentIndex >= totalSlides) {
currentIndex = 0;
} else if (currentIndex < 0) {
currentIndex = totalSlides - 1;
}
for (let i = 0; i < totalSlides; i++) {
slides[i].classList.remove("active");
}
slides[currentIndex].classList.add("active");
}
// Initial call to start the slideshow
showSlides();
function toggleMenu() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
document.addEventListener("DOMContentLoaded", function () {
var pathname = window.location.pathname;
var navLinks = document.querySelectorAll(".topnav a");
navLinks.forEach(function (link) {
if (link.getAttribute("href") === pathname.split("/").pop()) {
link.classList.add("active");
}
});
});
// Contact Form Functionality with EmailJS
document.getElementById("contactForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent the default form submission
// Initialize EmailJS
emailjs.init("BfYQtqbAmpqUEmFDF");
console.log("EmailJS initialized.");
// Prepare the template parameters
var templateParams = {
name: document.getElementById("name").value,
subject: document.getElementById("subject").value,
message: document.getElementById("message").value,
};
// Send the email using EmailJS
emailjs.send("service_ksnq0rd", "template_d1jme4h", templateParams)
.then(function(response) {
console.log("Email sent successfully:", response.status, response.text);
alert("Message sent successfully!");
}, function(error) {
console.error("Failed to send message:", error);
alert("Failed to send message. Please try again later.");
});
});