Home » Jquery » jquery – How to hide menu until after a user starts scrolling in WordPress-Exceptionshub

jquery – How to hide menu until after a user starts scrolling in WordPress-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

The purpose of this code is to hide the menu until a user starts scrolling and only do so for devices with viewports above 1000px. I’m doing this in WordPress.

At the moment I have to click the scroll bar and move a little for the menu to disappear which should not be the case. I need the menu to be hidden even without any action so that it now appears once the user begins scrolling.

jQuery(document).ready(function($) {
  $(window).on('scroll', function() {
    var y = $(window).scrollTop();
    var width = $(window).innerWidth();

    if (window.location.pathname == '/') {
      if (window.innerWidth > 1000) {
        if (y > 0) {
          $('#top').fadeIn();
          $('#header-space').fadeIn();
        } else {
          $('#top').fadeOut();
          $('#header-space').fadeOut();
        }
      }
    } else {}
  });
});
How to&Answer: