Skip to content

Commit

Permalink
[script] Detect scroll on wrapper now since wrapper is the new scroll…
Browse files Browse the repository at this point in the history
… context
  • Loading branch information
cszach committed Oct 16, 2023
1 parent 0e69e24 commit eabe6db
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
document.addEventListener('DOMContentLoaded', () => {
const wrapper = document.querySelector('.wrapper');
const navBar = document.querySelector('nav');
const navigationLinks = navBar.querySelectorAll('li');
const hamburgerCheckbox = navBar.querySelector('.peer');
Expand All @@ -17,11 +18,11 @@ document.addEventListener('DOMContentLoaded', () => {

// Navbar appears on scroll down and hides on scroll up

let lastScrollY = window.scrollY;
let lastScrollY = wrapper.scrollTop;

window.addEventListener('scroll', () => {
window.scrollY - lastScrollY > 0 ? hideNavBar() : showNavBar();
lastScrollY = window.scrollY;
wrapper.addEventListener('scroll', () => {
wrapper.scrollTop - lastScrollY > 0 ? hideNavBar() : showNavBar();
lastScrollY = wrapper.scrollTop;
});

function hideNavBar() {
Expand Down

0 comments on commit eabe6db

Please sign in to comment.