-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
129 lines (108 loc) · 3.51 KB
/
main.js
File metadata and controls
129 lines (108 loc) · 3.51 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
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
// Mobile nav toggle
const navToggle = document.querySelector(".nav-toggle");
const navLinks = document.querySelector(".nav-links");
if (navToggle && navLinks) {
navToggle.addEventListener("click", () => {
navLinks.classList.toggle("open");
});
navLinks.addEventListener("click", (e) => {
if (e.target.classList.contains("nav-link")) {
navLinks.classList.remove("open");
}
});
}
// Smooth scroll for nav links (extra control beyond CSS behavior)
document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
anchor.addEventListener("click", function (e) {
const targetId = this.getAttribute("href").slice(1);
const targetEl = document.getElementById(targetId);
if (!targetEl) return;
e.preventDefault();
const offset = 80; // navbar height
const rect = targetEl.getBoundingClientRect();
const targetPos = window.scrollY + rect.top - offset;
window.scrollTo({
top: targetPos,
behavior: "smooth",
});
});
});
// Scroll-triggered fade in / up effects (both directions)
const fadeSections = document.querySelectorAll(".fade-section");
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("visible");
} else {
// Remove visible when scrolling away so it animates again
entry.target.classList.remove("visible");
}
});
},
{
threshold: 0.15,
}
);
fadeSections.forEach((section) => observer.observe(section));
// Touch feedback for shiny buttons and cards
function addTapFeedback(selector) {
document.querySelectorAll(selector).forEach((el) => {
el.addEventListener(
"touchstart",
() => {
el.classList.add("tapped");
},
{ passive: true }
);
el.addEventListener("touchend", () => {
setTimeout(() => el.classList.remove("tapped"), 180);
});
});
}
addTapFeedback(".btn");
addTapFeedback(".card");
// Optional: slight scale on tap
const style = document.createElement("style");
style.innerHTML = `
.btn.tapped, .card.tapped {
transform: scale(0.97);
}
`;
document.head.appendChild(style);
const liquidBtn = document.getElementById('liquid-btn');
const form = document.querySelector('.contact-form');
liquidBtn.addEventListener('click', (e) => {
e.preventDefault();
// Shine animation
liquidBtn.classList.add('flash');
setTimeout(() => {
liquidBtn.classList.remove('flash');
}, 450);
// Custom Event trigger
const event = new Event('liquid-btn');
form.dispatchEvent(event);
});
// WhatsApp Redirect Handler
form.addEventListener('liquid-btn', function (event) {
event.preventDefault(); // Stop normal submit
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
const message = document.getElementById('message').value;
const whatsappNumber = "919583075623"; // Country code + Number
const whatsAppMsg = `Hello Abrar, I'm ${name}, My mail ID is ${email}.%0AMy query is that, ${message}.%0APlease send me the final Form.`;
const url = `https://wa.me/${whatsappNumber}?text=${whatsAppMsg}`;
window.open(url, "_blank").focus();
});
const btn = document.getElementById("blackGlassBtn");
btn.addEventListener("click", () => {
btn.classList.add("intense");
setTimeout(() => {
window.location.assign("#contact");
}, 250);
});
// Dynamic footer year
const yearSpan = document.getElementById("year");
if (yearSpan) {
yearSpan.textContent = new Date().getFullYear();
}