Add scrolled-top-top body class and script
This commit is contained in:
parent
45bf775d2d
commit
6fc9a8d3af
@ -64,7 +64,7 @@ if ( is_archive() || is_search() || is_404() ) {
|
||||
?>
|
||||
</head>
|
||||
|
||||
<body <?php body_class( 'site-bg' ); ?> data-post-id="<?php echo $post_id ?: -1; ?>">
|
||||
<body <?php body_class( 'site-bg scrolled-to-top' ); ?> data-post-id="<?php echo $post_id ?: -1; ?>">
|
||||
<?php wp_body_open(); ?>
|
||||
|
||||
<?php
|
||||
|
2
js/application.min.js
vendored
2
js/application.min.js
vendored
File diff suppressed because one or more lines are too long
@ -501,17 +501,21 @@ var /** @const {Number} */ fcn_lastScrollTop = 0;
|
||||
* on the difference. Updates the stored value afterwards for the next time.
|
||||
*
|
||||
* @since 4.0
|
||||
* @since 5.8.1 - Also checks whether the page is scrolled to the top.
|
||||
*/
|
||||
|
||||
function fcn_scrollDirection() {
|
||||
// Do not proceed if the mobile menu is open
|
||||
// Get current scroll offset
|
||||
const newScrollTop = window.scrollY ?? document.documentElement.scrollTop;
|
||||
|
||||
// Scrolled to top?
|
||||
fcn_theBody.classList.toggle('scrolled-to-top', newScrollTop === 0);
|
||||
|
||||
// Stop if the mobile menu is open
|
||||
if (fcn_theSite.classList.contains('transformed-scroll')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get current scroll offset
|
||||
const newScrollTop = window.scrollY ?? document.documentElement.scrollTop;
|
||||
|
||||
// Check whether the difference between old and new offset exceeds the threshold
|
||||
if (Math.abs(fcn_lastScrollTop - newScrollTop) >= 5) {
|
||||
fcn_theBody.classList.toggle('scrolling-down', newScrollTop > fcn_lastScrollTop);
|
||||
@ -523,6 +527,9 @@ function fcn_scrollDirection() {
|
||||
// Listen for window scrolling
|
||||
window.addEventListener('scroll.rAF', fcn_throttle(fcn_scrollDirection, 200));
|
||||
|
||||
// Initialize once
|
||||
fcn_scrollDirection();
|
||||
|
||||
// =============================================================================
|
||||
// OBSERVERS
|
||||
// =============================================================================
|
||||
|
Loading…
x
Reference in New Issue
Block a user