I have a hidden div, .model-detail-panel that is revealed when clicking .span.
$('[class*="span"]').on('click', function () {
$(this).parent().next('.model-detail-panel').slideToggle()
});
I want to incorporate .animate() into this code to scroll the screen so that the top of the revealed div is at the top of the window.
How can I achieve this?
Thanks in advance..
You can use Position, like this:
$("body, html").animate({
scrollTop: $(".model-detail-panel").position().top
});
Slightly changing the code suggested by @michele-bertoli to
$('html, body').animate({scrollTop: $(".model-detail-panel").offset().top
}, 500);
Has worked for me..
Thanks to those who posted..
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