Demo: http://jsfiddle.net/CLzfW/4/
$('.button').click(function(e){ e.preventDefault(); $('.expander').slideToggle(); $('html, body').animate({ scrollTop: 1000 }, 2000); });
Just use .expander height.
If you need this to be a 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); });
source share