Monday, February 26, 2024
 Popular · Latest · Hot · Upcoming
53
rated 0 times [  55] [ 2]  / answers: 1 / hits: 20766  / 11 Years ago, tue, september 3, 2013, 12:00:00

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/


More From » jquery

 Answers
14

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);
});

[#75920] Tuesday, September 3, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
maxinec

Total Points: 117
Total Questions: 116
Total Answers: 116

Location: Bangladesh
Member since Sat, Jan 23, 2021
3 Years ago
maxinec questions
;