0

I have a function where I enable scrolling only to for the difference of the div height and window height, so that it doesn't scroll down from the point where div ends. But that is not what I want, because if I resize the screen to smaller size, user is not able to scroll all the way down to the end of that particular div. How can I modify this so that I enable scrolling to the point where the div is visible and only to that point and not over it?

scrollPoint = $(".magazine-section").offset().top - $(window).height();

$(window).scroll(function() {
    $(window).scrollTop() > scrollPoint ? $(window).scrollTop(scrollPoint) : '';
}).scroll();
HudsonPH
  • 1,708
  • 2
  • 19
  • 34
Marco
  • 3,295
  • 9
  • 46
  • 99
  • Possible duplicate of [jQuery scroll to element](http://stackoverflow.com/questions/6677035/jquery-scroll-to-element) – Dekel Nov 02 '16 at 14:59

1 Answers1

2

You need to set scrollPoint again when the window is resized using $(window).resize().

$(window).resize(function() {
   scrollPoint = $(".magazine-section").offset().top - $(window).height();
}
Dan Wilson
  • 3,639
  • 2
  • 14
  • 26