how to stop menu when you stop scrolling

I can't figure out how to stop menu when you stop scrolling. When you scroll down menu has to hide and show only when stop scrolling or scrolling up. My code work only when you scroll up, I would appreciate if you help me.