1 Example(s) of Bootstrap Scrollspy


Description :

scrollspy is a plugin made by using bootstrap classes which is used to update the navigation bar automatically based on the position of scroll.


Bootstrap Scrollspy Example - 1
<!DOCTYPE html>
<html>
<head>
    <title>Bootstrap Example</title>
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <style>
        body {
            position: relative;
        }
        #part1 {
            padding-top: 50px;
            height: 400px;
            color: black;
            background-color: yellow;
        }

        #part2 {
            padding-top: 70px;
            height: 400px;
            color: black;
            background-color: yellowgreen;
        }

        #part3 {
            padding-top: 70px;
            height: 400px;
            color: black;
            background-color: red;
        }

        #part5 {
            padding-top: 70px;
            height: 400px;
            color: black;
            background-color: orange;
        }

        #part6 {
            padding-top: 70px;
            height: 400px;
            color: black;
            background-color: deeppink;
        }
    </style>
</head>
<body data-spy="scroll" data-target=".navbar">
    <nav class="navbar navbar-inverse navbar-fixed-top">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">Parts</a>
            </div>
            <div>
                <div class="collapse navbar-collapse" id="myNavbar">
                    <ul class="nav navbar-nav">
                        <li><a href="#part1">Part 1</a></li>
                        <li><a href="#part2">Part 2</a></li>
                        <li><a href="#part3">Part 3</a></li>
                        <li class="dropdown">
                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">part 4 <span class="caret"></span></a>
                            <ul class="dropdown-menu">
                                <li><a href="#part5">part 4-1</a></li>
                                <li><a href="#part6">part 4-2</a></li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </nav>
    <div id="part1" class="container-fluid">
        <h1>Part 1</h1>
        <p>Please looked at navigation bar while scrolling.</p>
    </div>
    <div id="part2" class="container-fluid">
        <h1>Part 2</h1> 
        <p>Please looked at navigation bar while scrolling.</p>
    </div>
    <div id="part3" class="container-fluid">
        <h1>Part 3</h1>
        <p>Please looked at navigation bar while scrolling.</p>
    </div>
    <div id="part5" class="container-fluid">
        <h1>Part 4 Submenu 1</h1>
        <p>Please looked at navigation bar while scrolling.</p>
    </div>
    <div id="part6" class="container-fluid">
        <h1>Part 4 Submenu 2</h1>
        <p>Please looked at navigation bar while scrolling.</p>
    </div>

</body>
</html>

Output