-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
122 lines (78 loc) · 2.71 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
// this is loader i have adder before that website will reload then it will launch it
var preloader = document.getElementById('preloader');
function myFunction(){
preloader.style.display = 'none';
}
//this will take you each part of navigation bar
const nav = document.querySelector(".navbar-item"),
navList = nav.querySelectorAll('li'),
totalNavList = navList.length,
allSection = document.querySelectorAll('.section'),
totalSection = allSection.length;
for(let i=0; i<totalNavList; i++) {
const a = navList[i].querySelector("a");
a.addEventListener("click" , function(){
for(let j =0; j< totalNavList ; j++) {
navList[j].querySelector('a').classList.remove("active");
}
this.classList.add("active");
nav.classList.add("close");
});
}
// ye code scroll pe har ek section pe move kar dega navigation bar ko easyly
window.addEventListener("scroll" , () => {
let fromTop = window.scrollY;
navListAnchor = nav.querySelectorAll("a");
navListAnchor.forEach(link => {
let section = document.querySelector(link.hash);
if(section.offsetTop <= fromTop && section.offsetTop + section.offsetHeight > fromTop){
link.classList.add("active");
}
else{
link.classList.remove("active");
}
});
});
//this is while we are using mobile phone all the section should be seen to us
if(window.innerWidth < 1200) {
burger = document.querySelector(".menu-btn");
console.log(burger);
burger.addEventListener("click", function(){
nav.classList.toggle("close");
})
}
// this is form validation cade when you are writing valid things or this will check by this code
var submitted = false;
function resetForm() {
document.getElementById('contact-form').reset();
document.getElementById('success').innerHTML = ""; // Clear success message
}
function validateForm() {
if (!validateName() || !validateEmail()) {
return false;
} else {
submitted = true;
var thankyou = 'Your Message Was Sent Successfully. Thanks!';
document.getElementById('success').innerHTML = thankyou;
return true;
}
}
function validateName() {
// Add your name validation logic here
var name = document.getElementById('name').value;
if (name.length === 0) {
alert("Name cannot be empty");
return false;
}
return true;
}
function validateEmail() {
// Add your email validation logic here
var email = document.getElementById('email').value;
var regex = /^\S+@\S+\.\S+$/;
if (!regex.test(email)) {
alert("Invalid email address");
return false;
}
return true;
}