Skip to content

Commit

Permalink
Created a functionality so that when scrolling down the navbar is hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneStanding committed Oct 1, 2024
1 parent 404f701 commit 955d89d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ <h5>Aligarh</h5>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe"
crossorigin="anonymous"></script>
<script src="./index.js"></script>
</body>

</html>
16 changes: 16 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
let lastScrollTop = 0;
const navbar = document.querySelector('.navbar');

window.addEventListener('scroll', function() {
let scrollTop = window.pageYOffset || document.documentElement.scrollTop;

if (scrollTop > lastScrollTop) {
// Scrolling down
navbar.style.top = '-80px'; // Adjust height accordingly
} else {
// Scrolling up
navbar.style.top = '0';
}

lastScrollTop = scrollTop;
});

0 comments on commit 955d89d

Please sign in to comment.