Im trying to scroll to the bottom of the div when the user clicks on a link to slide the div down.
I've tried using the scrollTo and animate
$('html, body').animate({
scrollTop: $("#elementID").offset().top
}, 2000);
but nothing happens
heres the fiddle
http://jsfiddle.net/CLzfW/29/
In jQuery, we can automatically use the scrollTop() and height() methods to scroll a page from top to bottom. For example, JQuery scroll to the bottom of div set the scrollTop property of a div's JavaScript to the value of scroll height property to scroll to the bottom of div.
how to scroll down to the bottom of a div using javascript. scrollToBottom(theElement); // The specified node scrolls to the bottom.
The slideDown() Method in jQuery is used to check the visibility of selected elements or to show the hidden elements. It works on two types of hidden elements: Elements hidden using jQuery methods. Elements hidden using display: none in CSS.
If you want to check whether the user has scrolled to the bottom of the page, you can use the scroll() jQuery event. The given code piece takes the top scroll of the window, so how much the page is scrolled down, it adds the height of the visible window and checks if it is equivalent to the height of the document.
Demo: http://jsfiddle.net/CLzfW/4/
$('.button').click(function(e){
e.preventDefault();
$('.expander').slideToggle();
$('html, body').animate({
scrollTop: 1000
}, 2000);
});
Just use your .expander height.
If you need this to be variable you can do this: http://jsfiddle.net/CLzfW/26/
var scroll_to = $('.expander').offset().top + $('.expander').height();
$('.button').click(function(e){
e.preventDefault();
$('.expander').slideToggle();
$('html, body').animate({
scrollTop: scroll_to
}, 2000);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With