I'm developing a hamburger menu for the mobile version of my site. You can see exactly how it works on this codepen: http://codepen.io/terrorsaurusrex/pen/gluFh
As you can see, you click the hamburger menu and the div with links expands downwards. If you scroll, the div collapses and the menu returns to it's initial state. This is the script telling the div to collapse if the window is scrolled:
$(window).scroll(function(event) //AUTOMATICALLY HIDES THE NAV WHEN SCROLLING STARTS
{
if($("#"+slideNavName).attr('class')=="revealed") //SEE IF YOUR NAV IS OPEN
{
//CHANGE ICON BACK INTO A HAMBURGER
$("#"+rectangleName+"1").toggleClass(showRect+" "+topRectX);
$("#"+rectangleName+"2").toggleClass(showRect+" "+hideRectX);
$("#"+rectangleName+"3").toggleClass(showRect+" "+bottomRectX);
//HIDE YOUR NAVIGATION
$("#"+slideNavName).toggleClass('revealed hidden');
}
});
I wish to put a horizontally scrollable div within the div that appears when pressing the hamburger button. Is there a way to rewrite this script so that the hamburger div only collapses when the window is scrolled vertically only, and remains when scrolled horizontally?
Thanks
codepen demo
Description
Simply detecting if the scroll is horizontal or vertical if it is horizontal ignore the scroll tasks.
JS