-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
87 lines (71 loc) · 2.81 KB
/
script.js
File metadata and controls
87 lines (71 loc) · 2.81 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
window.addEventListener('scroll', function () {
const header = document.querySelector('.header');
if (window.scrollY > 50) { // Adjust the 50px value based on when you want the blur to happen
header.classList.add('navblur');
} else {
header.classList.remove('navblur');
}
});
// loader on load remove
window.onload = function() {
var loadingAnimation = document.getElementById('loader_content');
window.scrollTo(0,0); //home on reloded
setTimeout(function() {
loadingAnimation.style.opacity = '0';
setTimeout(function() {
loadingAnimation.style.display = 'none';
}, 500);
}, 1000);
};
// Mobile menu toggle
document.addEventListener('DOMContentLoaded', function () {
const menuIcon = document.getElementById('menu');
const navbar = document.querySelector('.navbar');
menuIcon.addEventListener('click', function () {
navbar.classList.toggle('active');
// Change menu icon
if (navbar.classList.contains('active')) {
menuIcon.classList.remove('uil-bars');
menuIcon.classList.add('uil-times');
} else {
menuIcon.classList.remove('uil-times');
menuIcon.classList.add('uil-bars');
}
});
// Close menu -open menu
const navLinks = document.querySelectorAll('.navbar a');
navLinks.forEach(link => {
link.addEventListener('click', function () {
navbar.classList.remove('active');
menuIcon.classList.remove('uil-times');
menuIcon.classList.add('uil-bars');
});
document.addEventListener('click', function (event) {
if (!navbar.contains(event.target) && !menuIcon.contains(event.target) && navbar.classList.contains('active')) {
navbar.classList.remove('active');
menuIcon.classList.remove('uil-times');
menuIcon.classList.add('uil-bars');
}
});
});
// Active section link highlight
const sections = document.querySelectorAll('section');
function highlightNavLink() {
let scrollPosition = window.scrollY;
sections.forEach(section => {
const sectionTop = section.offsetTop - 100;
const sectionHeight = section.offsetHeight;
const sectionId = section.getAttribute('id');
if (scrollPosition >= sectionTop && scrollPosition < sectionTop + sectionHeight) {
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === '#' + sectionId) {
link.classList.add('active');
}
});
}
});
}
window.addEventListener('scroll', highlightNavLink);
highlightNavLink(); // Call on page load
});