Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

nav not change color on scroll

I have a problem. I tried to do so that when I go down the navbar changes color it worked but the problem is that when I go up to the level of the slider it stays in the color that it changed. In this link you will find the whole code https://jsfiddle.net/khdtc6bn/ this is my js code

$(document).ready(function(){
    $(window).scroll(function(){
        var scroll = $(window).scrollTop();
        if (scroll > 300) {
          $(".navbar-custom").css("background" , "blue");
        }
    })
  })

I would like that when I am all up it takes back this basic color, where is the problem in the code?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to change the color again if the scroll is less or equal 300:

$(document).ready(function(){
    $(window).scroll(function(){
        var scroll = $(window).scrollTop();
        if (scroll > 300) {
          $(".navbar-custom").css("background" , "blue");
        }
        else{
          $(".navbar-custom").css("background" , "rgba(255, 255, 255, 0.37)");
        }
    })
  })
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading