There is a misunderstanding here:
.off("scroll")
does not mean that a callback has to be invoked when the scroll ends.
Instead it detach the callback from the scroll
event.
What you want is invoke a callback when the scroll starts, invoke another one when it stops.
There are many ways to accomplish this.
This is my approach (the code is self-explaining):
$(document).on('scroll',scrollStart);
// A scroll has started
function scrollStart()
{
var lastScrollY;
// record the position
lastScrollY = $(window).scrollTop();
// hide the menu
hideMenu();
// detach the event. We don't want the callback called again for now.
$(document).off('scroll',scrollStart);
// let the function scrollRunning be called after 1 sec
setTimeout( function() { scrollRunning( lastScrollY ) }, 1000 );
}
// A scroll is going on. Or maybe has ended
function scrollRunning( lastScrollY )
{
var currentScrollY;
// current scroll position
currentScrollY = $(window).scrollTop();
// did the position change ? Scroll is going on
// schedule scrollRunning to check again after 1 sec
if( lastScrollY != currentScrollY ) // Scrolling is going on
{
lastScrollY = currentScrollY;
setTimeout( function() { scrollRunning( lastScrollY ) }, 1000 );
}
else // Scrolling has stopped. Show the menu and reattach the event
{
$(document).on('scroll',scrollStart);
showMenu();
}
}