-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimations.js
110 lines (94 loc) · 3.27 KB
/
animations.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
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
/* Image Slider
const images = document.querySelectorAll('.slider img');
const imageSrcs = ['pics/i1.jpg', 'pics/i2.jpg', 'pics/i3.jpg', 'pics/i4.jpg', 'pics/i5.jpg', 'pics/i6.jpg'];
images.forEach((image, i) => {
image.src = imageSrcs[i];
if (i === 0) {
image.style.display = 'block'; // Display the first image initially
}
});
let index = 0;
function changeImage() {
images[index].style.display = 'none';
index = (index + 1) % images.length;
images[index].style.display = 'block';
}
setInterval(changeImage, 3000); // Change image every 3 seconds
*/
let slider = document.querySelector(".slider");
let currentSlide = 0;
let totalSlides = slider.querySelectorAll(".wrapper .left > div").length - 1;
slider.querySelector(".controls .up").addEventListener("click", function () {
if (currentSlide == 0) {
return;
}
currentSlide--;
slider.querySelector(".wrapper .left div").style.marginTop = `${
currentSlide * -100
}vh`;
slider.querySelector(".wrapper .right div").style.marginTop = `${
(totalSlides - currentSlide) * -100
}vh`;
});
slider.querySelector(".controls .down").addEventListener("click", function () {
if (currentSlide == totalSlides) {
return;
}
currentSlide++;
slider.querySelector(".wrapper .left div").style.marginTop = `${
currentSlide * -100
}vh`;
slider.querySelector(".wrapper .right div").style.marginTop = `${
(totalSlides - currentSlide) * -100
}vh`;
});
// Smooth Scrolling
const navLinks = document.querySelectorAll('nav a');
navLinks.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const targetId = link.getAttribute('href');
const targetElement = document.querySelector(targetId);
targetElement.scrollIntoView({ behavior: 'smooth' });
});
});
// Animated Transitions between Sections
const sections = document.querySelectorAll('.section');
window.addEventListener('scroll', () => {
sections.forEach(section => {
const sectionTop = section.getBoundingClientRect().top;
if (sectionTop < window.innerHeight * 0.8) {
section.classList.add('active');
}
});
});
// Fade-In Effects for Elements
const fadeElements = document.querySelectorAll('.fade-in');
window.addEventListener('scroll', () => {
fadeElements.forEach(element => {
const elementTop = element.getBoundingClientRect().top;
if (elementTop < window.innerHeight * 0.8) {
element.classList.add('active');
}
});
});
// Form Validation
function validateForm() {
var nameInput = document.querySelector('.contact__input[name="name"]');
var emailInput = document.querySelector('.contact__input[name="email"]');
var messageInput = document.querySelector('.contact__input[name="message"]');
var name = nameInput.value.trim();
var email = emailInput.value.trim();
var message = messageInput.value.trim();
if (name === '' || email === '' || message === '') {
alert('All fields are required.');
return false;
}
// Basic email validation
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
if (!emailPattern.test(email)) {
alert('Please enter a valid email address.');
return false;
}
return true; // Allow form submission
}