You need to scroll the page down a little while scrolling down to a certain position.var scrollHeight = $('.header').height() + $('.main-slider').height();
and scroll the page to the very top if, when scrolling up, the window reaches the same position
HTML
<div class="main"> <div class="header main-page-header">header</div> <div class="main-slider">main-slider</div> </div> Jquery
var scrollHeight = $('.header').height() + $('.main-slider').height(); if ($('.header').hasClass('main-page-header')) { var lastScrollTop = 0; $(window).scroll(function () { var scrollTop = $(window).scrollTop(); if (scrollTop > lastScrollTop) { if (lastScrollTop === 0) { $("html, body").animate({ scrollTop: scrollHeight }, 600); } } if (scrollTop < lastScrollTop) { if (scrollTop < scrollHeight) { $("html, body").animate({ scrollTop: 0 }, 600); } } lastScrollTop = scrollTop; }); } The first part of the script, scrolling down to a certain position, works as it should, and when scrolling up, when the window reaches the right place, the page scrolls to the top, but then it becomes impossible to scroll down.
http://jsfiddle.net/qwvn7vpo/7/
How to make the code work correctly when scrolling up?