5
I’m using the technique of Marius Craciunoiu to display my entire navbar when the user scrolls the screen up.
So, here’s my code Javascript (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;
}
For ease, I put my code on http://jsfiddle.net/caio/7HrK7/. If you want to test on iOS, you’ll need to sign in via another address http://fiddle.jshell.net/caio/7HrK7/show/light/.
VIDEO: http://hiperload.com/s/ua5k53n0x/d.mp4?inline
As you can see, my code works on desktop and Android phones, but on iOS, you need to enter a touch event to respond while the scrolling event happens, or else the action will only be triggered at the end of the movement. I tried to add the event touchmove
, but without success. You can help me?