I'm using the Marius Craciunoiu technique to display all of my navbar when the user scrolls the screen up.
So here's my JavaScript code (using jQuery):
var delta, didScroll, lastScrollTop, navbarHeight;
delta = 5;
lastScrollTop = 0;
navbarHeight = $('.navbar').outerHeight();
$(window).on('scroll touchmove', function() {
didScroll = true;
});
setInterval(function() {
if (didScroll) {
hasScrolled();
didScroll = false;
}
}, 250);
function hasScrolled() {
var scrollTop = $(this).scrollTop();
if (Math.abs(lastScrollTop - scrollTop) <= delta) { return; }
if (scrollTop > lastScrollTop && scrollTop > navbarHeight) {
$('.navbar').addClass('scrolling');
} else {
if (scrollTop + $(window).height() < $(document).height()) {
$('.navbar').removeClass('scrolling');
}
}
lastScrollTop = scrollTop;
}
To make it easier, I've put my code in the link . If you want to test on iOS, you'll need to sign in at another link address.
VIDEO: link
As you can see, my code works on desktop and Android phones, but on iOS, it is necessary to insert a touch event to respond while the scrolling event happens, or else the action will only be triggered at the end of the move. I tried to add the touchmove
event, but to no avail. Can you help me?