简体   繁体   中英

Scroll to a div that has a margin-top of 100vh

I am trying to scroll to a div that has a margin-top:100vh

The reason why it has this is because it scrolls over a fixed page.

  $('html, body').animate({
    scrollTop:$("#sectAbout").offset().top
}, 1000);

By the way this is a responsive app, so it would need to work with any size screen.

Seems to be working fine to me, please make your question a bit more clear about what is not working.

 $('html, body').animate({ scrollTop:$("#sectAbout").offset().top }, 1000); 
 #sectAbout{ background-color:blue; margin-top:100vh; height:100vh; width:100% } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <section id="sectAbout"></section> 

$('html, body').animate({scrollTop:1200},'50');

您可以使用此代码,我认为它就像这样,只需尝试以下代码即可。

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