<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<title>Sticky NavBar With Scroll</title>
</head>
<body>
<!-- Header Area Start -->
<header class="header-section">
<div class="container">
<div class="row">
<div class="col-md-12">
<nav class="navbar navbar-expand-lg custom-navbar">
<a class="navbar-brand logo" href="#">Logo</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"><i class="fa fa-bars"></i></span>
</button>
<div class="collapse navbar-collapse menu" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Gallery</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Portfolio</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Blog</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
</div>
</header>
<!-- Header Area End -->
<section class="hero-section">
<div class="container">
<div class="row">
<div class="col-md-12 display">
<div class="hero-content text-center text-white">
<h1>This is Hero Area</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quis numquam ipsam eligendi atque. Ducimus sunt, hic doloribus cupiditate suscipit blanditiis.</p>
</div>
</div>
</div>
</div>
</section>
<!-- content Area Start -->
<section class="content-section">
<div class="container">
<div class="row ">
<div class="col-md-12">
<div class="content">
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
</div>
</div>
</div>
</div>
</section>
<!-- content Area End -->
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</body>
</html>
.header-section{
position: fixed;
width: 100%;
z-index: 999;
padding: 10px 0px;
}
.logo{
color: #fff !important;
}
.menu ul li {
font-size: 17px;
padding: 0px 10px;
}
.menu ul li a {
color: #fff !important;
}
.black{
background: #111E6C;
box-shadow: 0px 1px 7px 1px #111e6cc2;
}
.hero-section {
width: 100%;
height: 100vh;
background-image: url(https://i.postimg.cc/BZYnPt60/background-slider.jpg);
background-size: cover;
position: relative;
}
.display {
display: table;
}
.hero-content {
display: table-cell;
vertical-align: middle;
width: 100%;
height: 100vh;
}
.content {
margin: 4em auto;
font-size: 20px;
line-height: 30px;
text-align: justify;
}
@media(max-width: 786px) {
.header-section{
background: #111E6C;
box-shadow: 0px 1px 7px 1px #111e6cc2;
}
.menu ul li a {
text-align: center;
}
.showing {
max-height: 35em;
}
.menu-icon {
display: block;
}
.custom-navbar button:focus {
outline: none;
}
.custom-navbar .navbar-toggler-icon i {
color: #fff;
font-size: 24px;
}
.custom-navbar .navbar-toggler-icon {
text-align: center;
line-height: 30px;
}
}
$(window).on("scroll", function() {
if($(window).scrollTop()) {
$('.header-section').addClass('black');
}
else {
$('.header-section').removeClass('black');
}
})