Skip to content

Commit

Permalink
Create sciript.js
Browse files Browse the repository at this point in the history
  • Loading branch information
harikrishnan669 authored Jun 1, 2024
1 parent 7172646 commit 689c29f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions sciript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
let menuIcon = document.querySelector('#menu-icon');
let navbar = document.querySelector('.navbar');

let sections = document.querySelectorAll('section');
let navlinks = document.querySelectorAll('header nav ul li a');

window.onscroll = () => {
sections.forEach(sec => {
let top = window.scrollY;
let offset = sec.offsetTop - 150;
let height = sec.offsetHeight;
let id = sec.getAttribute('id');
if (top >= offset && top < offset + height) {
navlinks.forEach(link => {
link.classList.remove('active');
document.querySelector('header nav ul li a[href="#' + id + '"]').classList.add('active');
});
}
});
};

menuIcon.onclick = () => { // Changed oneClick to onclick
menuIcon.classList.toggle('bx-x');
navbar.classList.toggle('active');
};

0 comments on commit 689c29f

Please sign in to comment.