forked from Blaze-0903/sarthi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
saarthi.js
48 lines (40 loc) · 1.4 KB
/
saarthi.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
// Smooth scrolling for anchor links
document.addEventListener("DOMContentLoaded", function() {
const anchorLinks = document.querySelectorAll('a[href^="#"]');
anchorLinks.forEach(function(anchorLink) {
anchorLink.addEventListener("click", function(e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute("href"));
target.scrollIntoView({
behavior: "smooth"
});
});
});
});
// Add active class to the current navigation item
document.addEventListener("DOMContentLoaded", function() {
const sections = document.querySelectorAll("section");
window.addEventListener("scroll", function() {
let current = "";
sections.forEach(function(section) {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (pageYOffset >= sectionTop - sectionHeight / 3) {
current = section.getAttribute("id");
}
});
const navItems = document.querySelectorAll("nav ul li a");
navItems.forEach(function(item) {
item.classList.remove("active");
if (item.getAttribute("href").slice(1) === current) {
item.classList.add("active");
}
});
});
});
//popup
let popup=document.getElementById("popup");
function openPopup(){
popup.classList.add("open-popup");
}
// comment()