forked from Suchitra-Sahoo/AgriLearnNetwork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
137 lines (116 loc) · 3.84 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
let menuIcon = document.querySelectorAll('#menu-icon');
let navbar = document.querySelectorAll('.navbar');
let Contact = document.querySelectorAll('#contact');
let navContact = document.querySelectorAll('#nav--contact');
menuIcon.forEach(icon => {
icon.onclick = () => {
icon.classList.toggle('bx-x');
navbar.forEach(nav => nav.classList.toggle('active'));
}
});
// Add an "active" class to the clicked link
$('a[href*="#"]')
.not('[href="#"]')
.not('[href="#0"]')
.click(function(event) {
// Remove any existing "active" class from links
$('a').removeClass('active');
// Add "active" class to clicked link
$(this).addClass('active');
// Smooth scroll to target as before
if (
location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '')
&&
location.hostname == this.hostname
) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
if (target.length) {
event.preventDefault();
$('html, body').animate({
scrollTop: target.offset().top
}, 900, function() {
var $target = $(target);
$target.focus();
if ($target.is(":focus")) {
return false;
} else {
$target.attr('tabindex','-1');
$target.focus();
};
});
}
}
});
//when scroll on any section that section's corresponding hyperlink will be active and
// the previous activated hyperlink will be deactivated
$('section[id]').mouseover(function() {
var sectionId = $(this).attr('id');
var correspondingLink = $('a[href="#' + sectionId + '"]');
// Remove active class from all links
$('a').removeClass('active');
// Add active class to the corresponding link
correspondingLink.addClass('active');
});
// Set initial active link based on URL hash
$(document).ready(function() {
var hash = window.location.hash;
if (hash) {
$('a[href="' + hash + '"]').addClass('active');
}
let header=document.querySelectorAll('header');
header.classList.toggle('sticky',window.scrollY >100);
});
ScrollReveal({
reset:true,
distance:'80px',
duration:2000,
delay:200
});
ScrollReveal().reveal('.home-content, .heading',{ origin:'top' });
ScrollReveal().reveal('.home-img, .services-container, .portfolio-box, .contact form',{ origin:'bottom' });
ScrollReveal().reveal('.home-content h1, .about-img',{ origin:'left' });
ScrollReveal().reveal('.home-content p, .about-content',{ origin:'left' });
const typed=new Typed('.multiple-text',{
strings:['Sow','Learn','Grow' ],
typeSpeed:100,
backSpped:100,
backDelay:1000,
loop:true
});
const form = document.getElementById('contact-form');
form.addEventListener('submit', (event) => {
event.preventDefault();
// Access form fields
const fullName = form.querySelector('input[placeholder="Full Name"]').value.trim();
const email = form.querySelector('input[placeholder="Email Address"]').value.trim();
const mobileNumber = form.querySelector('input[placeholder="Mobile Number"]').value.trim();
const emailSubject = form.querySelector('input[placeholder="Email Subject"]').value.trim();
const message = form.querySelector('textarea').value.trim();
// Validation
if (!fullName) {
alert('Please enter your full name.');
return;
}
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailPattern.test(email)) {
alert('Please enter a valid email address.');
return;
}
const mobilePattern = /^\d+$/;
if (!mobilePattern.test(mobileNumber)) {
alert('Please enter a valid mobile number.');
return;
}
if (!emailSubject) {
alert('Please enter the email subject.');
return;
}
if (!message) {
alert('Please enter your message.');
return;
}
// form reset
form.reset();
alert('Your message has been sent. Thank you!');
});