jQuery: move window viewport to show freshly toggled element
Check out the scrollTo jQuery plugin. You can simply do something like this:
$.scrollTo('div#addnote-area');
Or, if you want to animate it, provide the # of milliseconds for the scrolling to last:
$.scrollTo('div#addnote-area', 500);
Without the scrollTo plugin
$(window).scrollTop($('div#addnote-area').offset().top)
EDIT: Well I sure get a lot of points from this old answer :)
Here's a bonus, this can also be animated.
Just use the animate()
function and target the body tag:
$('body').animate({scrollTop:$('div#addnote-area').offset().top},500)
Try it on Stackoverflow! Open the inspector console and run
$('body').animate({scrollTop:$('#footer').offset().top},500)