Bootstrap 4 Scrollspy在div中的导航项不起作用

时间:2018-07-23 16:53:24

标签: html css twitter-bootstrap bootstrap-4 scrollspy

我似乎无法使工作通俗易懂。我在有时隐藏的div项中有一个导航项。此导航项需要具有工作滚动功能。我不确定问题是否与活动类有关。单击链接时,它不会变为活动状态。滚动到该部分也不起作用。

main-page.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <!-- can be dropped but must appear because of bootstrap warning -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>My title</title>
    <link rel="stylesheet" href="styles.css">
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">

    <!-- jQuery library -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

    <!-- Popper JS -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"> </script>

    <!-- Latest compiled JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
    <!-- JavaScript code for this page -->
    <script src="main_page.js"></script>
</head>
<body>
    <!-- A navbar that is always on top -->
    <nav class="navbar navbar-expand-sm fixed-top">...</nav>
<div class="container-fluid">
<!-- Content that shows up when navigating to the site or when the logo is clicked -->
        <div id="landing-page">...</div>
<!-- Shows all the Features of this product -->
        <div id="features-page" hidden=true data-spy="scroll" data-target="features-navbar" data-offset="1">
            <div class="jumbotron features-jumbotron text-center">
                something
            </div>
            <!-- Navbar in question -->
            <nav class="navbar navbar-expand-sm justify-content-center sticky-top" id="features-navbar">
                <div class="gray-border">
                    <div class="collapse navbar-collapse">
                        <ul class="navbar-nav  mr-auto">
                            <li class="nav-item">
                                <a class="nav-link nav-button active" href="#lease-feature">Lease</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link nav-button" href="#finance-feature">Finances</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link nav-button" href="#organized-feature">Organized</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link nav-button" href="#community-feature">Community</a> 
                            </li>
                        </ul>
                    </div>
                </div>
            </nav>
            <div class="feature-item" id="lease-feature">
                lease-feature
                <br/>
                <br/>
                <br/>
                <br/>
                <br/>
                lease-feature end
            </div>
            <div class="feature-item" id="finance-feature">
                Finance
                <br/>
                <br/>
                <br/>
                <br/>
                <br/>
                <br/>
                <br/>
                Finance end
            </div>
            <div class="feature-item" id="organized-feature">
                organized
                <br/>
                <br/>
                <br/>
                <br/>
                <br/>
                <br/>
                <br/>
                <br/>
                organized end
            </div>
            <div class="feature-item" id="community-feature">
                community-feature
                <br/>
                <br/>
                <br/>
                <br/>
                <br/>
                <br/>
                <br/>
                <br/>
                community-feature end
            </div>
            end
        </div>
 </div>
</body>
</html>

styles.css

body { 
    padding-top: 110px;
}

nav{
    background-color: white;
}
.nav-button{
    color: black;
}

.active{
    border-left: 2px solid black;
}

.gray-border{
    border-top: .1px solid #d9d9d9;
    border-bottom: .1px solid #d9d9d9;
}

.feature-item{
    padding-top: 220px;
}

...

1 个答案:

答案 0 :(得分:1)

问题是我缺少一个#,样式为div data-spy,而活动类属于li标记。

public void Stop()
{
    if(clockPin != null )
    {
        clockPin.Dispose();
    }

    if(dataPin != null)
    {
        dataPin.Dispose();
    }
}