Created
July 12, 2019 09:46
-
-
Save ivanmarkovich/50414c784735d75b84a42931e90c8950 to your computer and use it in GitHub Desktop.
Плавающая шапка появляется при скролле сайта вверх после n скролов
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Плавающая шапка появляется при скролле сайта вверх после n скролов | |
// =========== FLOATING HEADER | |
var pageYPos = window.pageYOffset; | |
var scrollUpTime = 0; | |
$(document).on('scroll',function(e){ | |
let scrollDirection = ( (window.pageYOffset - pageYPos) > 0 ) ? 'down' : 'up'; | |
pageYPos = window.pageYOffset; | |
scrollUpTime++; | |
if ( scrollDirection === 'up' && window.pageYOffset < 700 ) { | |
$('#floating-header').fadeOut(300, function(){ | |
$(this).removeClass('d-flex'); | |
}); | |
scrollUpTime = 0; | |
} | |
else if ( scrollDirection === 'up' && window.pageYOffset > 700 && scrollUpTime > 20 ) { | |
$('#floating-header').fadeIn(300).addClass('d-flex'); | |
} | |
else if ( scrollDirection === 'down' ) { | |
$('#floating-header').fadeOut(300, function(){ | |
$(this).removeClass('d-flex'); | |
}); | |
scrollUpTime = 0; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment