Skip to content

Commit

Permalink
refactor: Collapse navbar without jquery
Browse files Browse the repository at this point in the history
  • Loading branch information
AiyionPrime committed Jan 2, 2025
1 parent a42da6d commit 7366fd6
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions js/grayscale.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
* For details, see http://www.apache.org/licenses/LICENSE-2.0.
*/

// jQuery to collapse the navbar on scroll
$(window).scroll(function () {
if ($(window).scrollTop() > $("header").outerHeight()) {
$(".navbar-custom").addClass("fixed-top");
$(".navbar-custom").css("background-color", "rgba(0,0,0,0.61)");
} else {
$(".navbar-custom").removeClass("fixed-top");
$(".navbar-custom").css("background-color", "rgba(0,0,0,1)");
}
document.addEventListener("DOMContentLoaded", function () {
const navbar = document.querySelector(".navbar-custom");

// event listener to collapse the navbar on scroll
window.addEventListener("scroll", function () {
if (window.scrollY > document.querySelector("header").offsetHeight) {
navbar.classList.add("fixed-top");
navbar.style.backgroundColor = "rgba(0,0,0,0.61)";
} else {
navbar.classList.remove("fixed-top");
navbar.style.backgroundColor = "rgba(0,0,0,1)";
}
});
});

// jQuery for page scrolling feature - requires jQuery Easing plugin
Expand Down

0 comments on commit 7366fd6

Please sign in to comment.