简体   繁体   English

如何将页面部分锚定在滚动显示的导航栏底部?

[英]How to anchor a page-section to the bottom of a navigation bar that appears on scroll?

I have a single page website (Squarespace - Pacific template) https://pacific-demo.squarespace.com/?nochrome=false with a Navigation bar at the top that scrolls away with the home-page and appears again once you scroll to the first-section. 我有一个单页网站(Squarespace-Pacific模板) https://pacific-demo.squarespace.com/?nochrome=false ,顶部带有导航栏,该导航栏随主页滚动,一旦滚动到第一部分。 All the links are anchored to the correspondent section that slides up and stops in line with the Navigation Bar that appears on scroll. 所有链接都锚定到对应的部分,该部分向上滑动并与滚动条上显示的导航栏一致。

I would like to add a link to the home-page with an arrow that sends you down only to the first-section and aligns this with the appearing navigation bar. 我想用箭头添加到主页的链接,该箭头仅将您发送到第一部分,并将其与出现的导航栏对齐。 With a simple anchor link the section scrolls to the top of the browser behind the Navbar. 通过简单的锚点链接,该部分滚动到导航栏的导航器顶部。

I tried this script (adding one for each media-query I used) and it works, but if I resize the browser, the Navbar disappears, so I'd like to use something different. 我尝试了此脚本(为我使用的每个媒体查询添加一个脚本),它可以工作,但是如果我调整浏览器的大小,导航栏就会消失,因此我想使用其他脚本。

 if($(window).width() < 1438)
{
$("#arrow-down").click(function() {
    $('html,body').animate({
        scrollTop: $("#officina-page").offset().top -120},
        'slow');
});
}

    else if($(window).width() > 1439 && $(window).width() < 1558)
{
   $("#arrow-down").click(function() {
    $('html,body').animate({
        scrollTop: $("#officina-page").offset().top -130},
        'slow');
});
} 

You can do something like this with the good offset (height of your menu): 您可以使用良好的偏移量(菜单高度)来执行以下操作:

if($(window).width() > 1438) {
    $(function() {
      $('a[href*=#]').on('click', function(e) {
        e.preventDefault();
        $('html, body').animate({ scrollTop: $($(this).attr('href')).offset().top}, 500, 'linear');
      });
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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