简体   繁体   English

固定的导航栏隐藏网页内容

[英]Fixed navbar hides web content

I have a problem with a fixed navbar, I'm using Foundation 5 framework but it doesn't matter, because I have the same problem with or without the framework, I'm making a website only using one file HTML all sections in the same file, this is what I have and what I would like to see: 我使用固定的导航栏时遇到问题,我使用的是Foundation 5框架,但这没关系,因为无论是否使用该框架,我都存在相同的问题,我只使用一个文件HTML来制作网站,同一文件,这就是我所拥有的以及我希望看到的:

在此处输入图片说明

But unfortunately I got this when I clicked the option "Software": 但是不幸的是,当我点击选项“软件”时,我得到了这个:

在此处输入图片说明

As you can see the word "software" of the web content is hide by the navbar, I can see it only if I do scrolling manually. 如您所见,导航栏隐藏了Web内容中的“软件”一词​​,只有手动滚动时,我才能看到它。

This is my javascript code: 这是我的JavaScript代码:

$(function(){
$('ul li a').on('click',function(e){
    e.preventDefault();
    var strAncla = $(this).attr('href');

    $('body,html').stop(true ,true).animate({
        scrollTop: $(strAncla).offset().top
    }, 500);
});

}); });

I hope you can help me, thanks. 希望您能帮助我,谢谢。

The position: fixed attribute removes an element from the normal flow. position: fixed属性从常规流中删除一个元素。 What you probably need to do is tell it to scroll to the target position, minus the height of the navbar . 您可能需要做的就是告诉它滚动到目标位置, 减去导航栏的高度 So, for example: 因此,例如:

$(function(){
    $('ul li a').on('click',function(e){
        e.preventDefault();
        var strAncla = $(this).attr('href');

        $('body,html').stop(true ,true).animate({
            scrollTop: $(strAncla).offset().top - $('#scrollbarSelector').height()
        }, 500);
    });
});

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

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