bootstrap默认导航栏doestn正常工作

时间:2018-02-08 09:19:31

标签: javascript html css

Bootstrap DEFAULT-navbar跳转到我的部分#point下的几个像素,无论如何AFFIX-navbar工作得很好。

您可以在此处查看:http://kresyproduction.cz/

问题是,当我点击默认导航栏中的任何链接时,它不会以正确的方式滚动。就像你在我的页面上看到的一样。该部分下面几乎没有像素,它隐藏了一些内容。但是,当您滚动一点并且默认导航栏更改为词缀链接时,工作完美。

<!DOCTYPE html>
<html lang="cs">
<head>
<meta charset="UTF-8">
    <title>Kresy Production</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="img/favicon.png">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/font-awesome.min.css">
    <script src="js/jquery-1.12.4.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.0.4/popper.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">
</script>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js">
</script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js">
</script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
&& location.hostname == this.hostname) {
  var target = $(this.hash);
  target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
  if (target.length) {
    $('html,body').animate({
      scrollTop: target.offset().top
    }, 1000);
    return false;
  }
}
});
});
</script>

</head>
<body>
<nav class="navbar navbar navbar-default navbar-static-top" data-spy="affix" data-offset-top="50">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#domu"><img src="img/kp_white.png" alt="logo" title="Kresy Production" style="width auto;height: 30px;"></a>
            </div>

<!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav navbar-right">
                <li><a href="#domu">Domů</a></li>
                <li><a href="#sluzby">Služby</a></li>
                <li><a href="#showreel">Showreel</a></li>
                <li><a href="#onas">O nás</a></li>
                <li><a href="#kontakt">Kontakt</a></li>
            </ul>
            </div><!-- /.navbar-collapse -->
        </div><!-- /.container-fluid -->
    </nav>
</div>
.
.
</body>

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

您的导航栏具有数据偏移顶部值。这导致了这个问题。改变这个

    <nav class="navbar navbar-default nav-fixed-top" data-spy="affix" data-offset-top="50">

到此 -

    <nav class="navbar navbar-default nav-fixed-top" data-spy="affix" >

希望这会有所帮助......

编辑:1而不删除data-offset-top值,将其编辑为此

    <nav class="navbar navbar-default navbar-fixed-top" data-spy="affix" data-offset-top="xx">  -- xx could be the data offset that works for you.