Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

auto scroll to bottom when overflow auto

Tags:

does anyone know how to automatically jump to the bottom of a scrollable area by event in jquery ( or even javascript if no easy jquery solution)?

regards

like image 576
Phil Jackson Avatar asked Mar 27 '10 20:03

Phil Jackson


People also ask

How do I make overflow scroll automatically?

What you need to do is use the clearInterval() function when it gets to the top, set the scrollbar to the bottom of the page, then reset the interval using setInterval(). To detect when the scrollbar is at the top of the document/element depends on the browser.

How do you scroll to the bottom of a page automatically?

To use you just need to press CTRL+ Left click of your mouse and drag the mouse a bit in the direction you want to scroll the page. For example, if you want to scroll up to the page automatically, click CTRL+ left click and slightly move your mouse upwards, the tool will start scrolling up the page.

How do I keep my Div scrolled to the bottom?

use css position top keep it at the bottom {position : relative; bottom:0;} . Remove the css property once the user has scroll.


1 Answers

<div id="myDiv" style="height:300px;overflow:auto;">     <p>my content here</p> </div>  var myDiv = $("#myDiv"); myDiv.animate({ scrollTop: myDiv.attr("scrollHeight") - myDiv.height() }, 3000); 

Edit:

jQuery 1.6 introduced .prop and changed the meaning of .attr thus $("#someDiv").attr("scrollHeight") won't work anymore.

Need to be changed to: $("#someDiv").prop("scrollHeight")

Reference.

like image 119
PetersenDidIt Avatar answered Sep 29 '22 00:09

PetersenDidIt