简体   繁体   中英

Scroll Div to top of Page

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM