Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does jQuery have any functions to scroll the client to the bottom of the view port?

I want to animate a scroll to the bottom of the viewport with jQuery. Is there a plugin available which isn't overkill (i.e. without a huge feature set for this small task);

Is there a plugin available or a way to do this natively with jQuery?

like image 568
alex Avatar asked Mar 19 '09 04:03

alex


People also ask

How can check scroll bottom in jQuery?

scroll(function() { if($(window). scrollTop() + window. innerHeight == $(document). height()) { alert("bottom!"); } });

How do I scroll to the top of the page using jQuery?

In jQuery, the scrollTo() method is used to set or return the vertical scrollbar position for a selected element. This behavior can be used to scroll to the top of the page by applying this method on the window property. Setting the position parameter to 0 scrolls the page to the top.

How do I check if a div is scrolled to the bottom?

To detect when a user scrolls to bottom of div with React, we can check if the sum of the scrollTop and clientHeight properties of a scrollable element is equal to the scrollHeight property of the same element. We call the useRef hook to create a ref and we assign the returned ref to the inner div, which is scrollable.

How do you find end of scroll?

To detect scroll end with JavaScript, we can listen to the scroll event. Then in the event listener, we check if offsetHeight + scrollTop is bigger than or equal to scrollHeight . We get the div with document. querySelector .


1 Answers

jQuery makes things like this so trivial that you just dont need a plugin. Example:

var x = 250; //insert your own formula to calculate where you want to scroll to in px
var t = 500; //arbitrary time in ms
$("html,body").animate({ scrollTop: x }, t);

Instead of html,body you can put any element which scrolls, like a div. t is the time in ms over which the animation will run and x is your position to scroll to in px. Note that this works with scrollLeft also but not scrollRight or scrollBottom (not a limitation of jQuery but JavaScript).

like image 173
Darko Z Avatar answered Nov 04 '22 13:11

Darko Z