Reputation: 19
I am trying to get a div to scroll to the top of the page when it begins to slideDown()
. It's not doing what I intended, in fact I don't think it is doing anything at all.
Do I have the correct syntax to do a slideDown()
and scrollTop()
together?
jQuery('.pp-post-container').hide();
var prevPostID;
jQuery('.pp-post-banner-overlay').on('click', function() {
let postFullID = jQuery(this).attr('id');
let postNumID = postFullID.slice(23);
jQuery('#pp-post-' + prevPostID).slideDown(1000);
jQuery('#pp-post-container-' + prevPostID).slideUp(1000);
jQuery('#pp-post-' + postNumID).slideUp(1000);
jQuery('#pp-post-container-' + postNumID).slideDown(1000).scrollTop();
prevPostID = postNumID;
});
Upvotes: 0
Views: 216
Reputation: 12478
scrollTop()
without arguments will return the current vertical position.
If you want to scroll to top, you have to pass the value, that is 0 to the function.
scrollTop(0)
Read scrollTop with value in jQuery documentaion
Upvotes: 3