-2

I need a div to hide on body horizontal scroll I apply the below code which is working fine on vertical scroll how to apply the same code for bottom scroll ?

<script>
        $(window).scroll(function () {
            if ($(this).scrollTop() > 0) {
                $('.nk-sidebar').fadeOut();
            } else {
                $('.nk-sidebar').fadeIn();
            }
        });
    </script>
Aly-Elgarhy
  • 1,169
  • 1
  • 10
  • 14

1 Answers1

0

Try this code :

$(window).scroll(function() {
  var windowHeight = $(window).height();
  var documentHeight = $(document).height();
  var scrollPosition = $(document).scrollTop();

  if (scrollPosition + windowHeight >= documentHeight) {
    // Bottom scroll reached
    $('.nk-sidebar').fadeOut();
  } else {
    $('.nk-sidebar').fadeIn();
  }
});
mplungjan
  • 169,008
  • 28
  • 173
  • 236