Changing backgroud color of nav when scrolling up


I have a navigation bar that disappears when scrolling down, but reappears as soon as the user scrolls up. I want to change the background color when the nav reappears as by defaults its a transparent background. here is my nav code and .js

   <!-- Navigation -->
		<nav class="nav-down navbar navbar-default navbar-fixed-top">
			<div class="container-fluid">
				<!-- Brand and toggle get group,argined for better mobile display -->
				<div class="navbar-header">
					<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
					<span class="sr-only">Toggle navigation</span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
				<!-- Collect the nav links, forms, and other content for toggling -->
				<div class="collapse navbar-collapse" style="padding-top: 120px;">
					<ul class="nav navbar-nav">
				        <li class=""><a href="index.php">HOME</a></li>
					    <li class=""><a href="about-us.php">ABOUT US</a></li> 
						<li class=""><a href="fleet.php">FLEET</a></li> 
						<li class=""><a href="charter.php">CHARTER</a></li> 
						<li class=""><a href="aircraft-leasing.php">AIRCRAFT LEASING</a></li> 
						<li class=""><a href="specialized-services.php">SPECIALIZED SERVICES</a></li> 
						<li class=""><a href="contact.php">CONTACT</a></li> 
				<!-- /.navbar-collapse -->
			<!-- /.container-fluid -->

and the .js

// Hide Header on on scroll down
var didScroll;
var lastScrollTop = 0;
var delta = 2;
var navbarHeight = $('nav').outerHeight();

    didScroll = true;

setInterval(function() {
    if (didScroll) {
        didScroll = false;
}, 50);

function hasScrolled() {
    var st = $(this).scrollTop();
    // Make sure they scroll more than delta
    if(Math.abs(lastScrollTop - st) <= delta)
    // If they scrolled down and are past the navbar, add class .nav-up.
    // This is necessary so you never see what is "behind" the navbar.
    if (st > lastScrollTop && st > navbarHeight){
        // Scroll Down
    } else {
        // Scroll Up
        if(st + $(window).height() < $(document).height()) {
    lastScrollTop = st;

Any help would be greatly appreciated.


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.