Skip to content

Commit

Permalink
#1252 sticky header when scroll up show scroll down hide
Browse files Browse the repository at this point in the history
  • Loading branch information
FitoreGashi committed Jul 31, 2023
1 parent 1ad8e25 commit c2c7bd7
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Wordpress-Theme für zentrale Einrichtungen der Friedrich-Alexander-Universität
## Version


Version: 2.3.34-203
Version: 2.3.34-209



Expand Down
2 changes: 1 addition & 1 deletion js/fau-theme.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "FAU-Einrichtungen",
"textdomain": "fau",

"version": "2.3.34-208",
"version": "2.3.34-209",

"keywords": [
"WordPress",
Expand Down
2 changes: 1 addition & 1 deletion print.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions src/js/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,43 @@ $html.removeClass('no-js').addClass('js');
$('.meta-search .searchform input[type="text"]').toggleClass('active');
});



//scroll up hide show headder


let lastScrollTop = 0;

window.addEventListener("scroll", function() {
let scrollTop = window.pageYOffset || document.documentElement.scrollTop;
let header = document.getElementById('headerwrapper'); // Cache the element for performance

// If the user is at the very top of the page
if (scrollTop === 0) {
header.style.position = "static";
header.style.top = "auto"; // Reset the top property
}
// If scrolling up and current scroll position is not at the very top
else if (scrollTop < lastScrollTop) {
header.style.top = "0";
header.style.position = "fixed";
}
// If scrolled down more than 150px
else if (scrollTop < 250) {
header.style.top = "0";
header.style.position = "static";

}
// If it's within the first 150px while scrolling down
else {
header.style.top = "-100%";
header.style.position = "fixed";
}

lastScrollTop = scrollTop;
});


}
);

3 changes: 2 additions & 1 deletion src/sass/structure/header/_meta.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
}

#headerwrapper {
position: sticky;
position: static;
width: 100%;
top: 0;
z-index: 150;
transition: box-shadow 0.2s;
Expand Down
5 changes: 3 additions & 2 deletions style.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@charset "UTF-8";
/*!
Theme Name: FAU-Einrichtungen
Version: 2.3.34-208
Version: 2.3.34-209
Requires at least: 6.1
Tested up to: 6.2
Requires PHP: 8.0
Expand Down Expand Up @@ -9106,7 +9106,8 @@ body.embedded .news-item .news-meta {
}

#headerwrapper {
position: sticky;
position: static;
width: 100%;
top: 0;
z-index: 150;
transition: box-shadow 0.2s;
Expand Down

0 comments on commit c2c7bd7

Please sign in to comment.