content logo

Bootstrap Headers:

Bootstrap Scrollspy Headings

You may have been looking for a text in an article or website, but you could not find it. In this post, we have provided a code with the same purpose and you can find your needed information as soon as possible. The Bootstrap Scrollspy Headings is presented here with a great performance. If you want to find a heading on your website, the Bootstrap Header Code can be helpful. This HTML Header Code helps you to save time and find the related information in a short time. Most website administrations use this code to attract new audiences and interest older visitors.

As you see from the preview, this Bootstrap Scrollspy Code contains three sections with blue color. The dropdown part has a slide bar where you can choose your selected header. This code has a white background and as you select an item, its background changes to blue and the text turns white. After these changes, you will guide to the selected heading. By using this Auto Scrolling with Header, you can move to the headers easily. This code contains many headers and if you click on an icon, you can see its text as soon as possible. So, you can use this code on your website.

#

Auto Scrolling with Header

#

Bootstrap Header Code

#

HTML Header Code

#

Bootstrap Scrollspy Code

<!-- This script got from frontendfreecode.com -->
<nav id="navbar-example2" class="navbar navbar-light bg-light px-3 sticky-top">
    <a class="navbar-brand" href="#">Navbar</a>
    <ul class="nav nav-pills">
        <li class="nav-item">
            <a class="nav-link" href="#scrollspyHeading1">First</a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="#scrollspyHeading2">Second</a>
        </li>
        <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Dropdown</a>
            <ul class="dropdown-menu">
                <li><a class="dropdown-item" href="#scrollspyHeading3">Third</a></li>
                <li><a class="dropdown-item" href="#scrollspyHeading4">Fourth</a></li>
                <li>
                    <hr class="dropdown-divider">
                </li>
                <li><a class="dropdown-item" href="#scrollspyHeading5">Fifth</a></li>
            </ul>
        </li>
    </ul>
</nav>
<div data-bs-spy="scroll" data-bs-target="#navbar-example2" data-bs-offset="0" class="scrollspy-example" tabindex="0">
    <p class="m-5">...</p>
    <h4 id="scrollspyHeading1">First heading</h4>
    <p class="m-5">...</p>
    <h4 id="scrollspyHeading2">Second heading</h4>
    <p class="m-5">...</p>
    <h4 id="scrollspyHeading3">Third heading</h4>
    <p class="m-5">...</p>
    <h4 id="scrollspyHeading4">Fourth heading</h4>
    <p class="m-5">...</p>
    <h4 id="scrollspyHeading5">Fifth heading</h4>
    <p>...</p>
</div><a style="font-size: 8pt; text-decoration: none" target="_blank" href="http://frontendfreecode.com">Free Frontend</a>
                                                                            
body {
	position: relative;
}
@media (min-width: 992px) {
	.float-wrap.scroll-anim {
		transform: translateZ(0);
	}
	.float-wrap.animated {
		transform: none;
	}
	.float-wrap.scroll-anim .floating {
		position: absolute;
		top: 0;
		right: 0;
		transform: translate(0, 0);
	}
	.float-wrap.animated .floating {
		position: fixed;
		top: 0;
		right: 0;
	}
}
/* Listen to scroll to change header opacity class */
var scrollSpy = new bootstrap.ScrollSpy(document.body, {
    target: "#navbar-example2"
});
function checkScroll() {
    var startY = $(".scroll-anim").height() * 1; //The point where the navbar changes in px
    if ($(window).scrollTop() > startY) {
        $(".scroll-anim").addClass("animated");
    } else {
        $(".scroll-anim").removeClass("animated");
    }
}
if ($(".scroll-anim").length > 0) {
    $(window).on("scroll load resize", function () {
        checkScroll();
    });
}
<link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js'></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- This script got from frontendfreecode.com -->

<link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js'></script>
<style>
body {
	position: relative;
}
@media (min-width: 992px) {
	.float-wrap.scroll-anim {
		transform: translateZ(0);
	}
	.float-wrap.animated {
		transform: none;
	}
	.float-wrap.scroll-anim .floating {
		position: absolute;
		top: 0;
		right: 0;
		transform: translate(0, 0);
	}
	.float-wrap.animated .floating {
		position: fixed;
		top: 0;
		right: 0;
	}
}
</style>

</head>
<body>
<nav id="navbar-example2" class="navbar navbar-light bg-light px-3 sticky-top">
    <a class="navbar-brand" href="#">Navbar</a>
    <ul class="nav nav-pills">
        <li class="nav-item">
            <a class="nav-link" href="#scrollspyHeading1">First</a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="#scrollspyHeading2">Second</a>
        </li>
        <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Dropdown</a>
            <ul class="dropdown-menu">
                <li><a class="dropdown-item" href="#scrollspyHeading3">Third</a></li>
                <li><a class="dropdown-item" href="#scrollspyHeading4">Fourth</a></li>
                <li>
                    <hr class="dropdown-divider">
                </li>
                <li><a class="dropdown-item" href="#scrollspyHeading5">Fifth</a></li>
            </ul>
        </li>
    </ul>
</nav>
<div data-bs-spy="scroll" data-bs-target="#navbar-example2" data-bs-offset="0" class="scrollspy-example" tabindex="0">
    <p class="m-5">...</p>
    <h4 id="scrollspyHeading1">First heading</h4>
    <p class="m-5">...</p>
    <h4 id="scrollspyHeading2">Second heading</h4>
    <p class="m-5">...</p>
    <h4 id="scrollspyHeading3">Third heading</h4>
    <p class="m-5">...</p>
    <h4 id="scrollspyHeading4">Fourth heading</h4>
    <p class="m-5">...</p>
    <h4 id="scrollspyHeading5">Fifth heading</h4>
    <p>...</p>
</div><div id="bcl"><a style="font-size:8pt;text-decoration:none;" href="http://www.devanswer.com">Free Frontend</a></div>
<script>
/* Listen to scroll to change header opacity class */
var scrollSpy = new bootstrap.ScrollSpy(document.body, {
    target: "#navbar-example2"
});
function checkScroll() {
    var startY = $(".scroll-anim").height() * 1; //The point where the navbar changes in px
    if ($(window).scrollTop() > startY) {
        $(".scroll-anim").addClass("animated");
    } else {
        $(".scroll-anim").removeClass("animated");
    }
}
if ($(".scroll-anim").length > 0) {
    $(window).on("scroll load resize", function () {
        checkScroll();
    });
}
</script>

</body>
</html>
Preview