Make the background of the navigation bar to change when scrolling

1901 views javascript

I have a navigation bar on a website that i am making. I want to change the colour of the bar after the page scrolls about 500 pixels. How would i code that using javascript?

answered question

Welcome to SO! Please read How to Ask so you can receive an adequate solution.

1 Answer


You can do this by adding a scroll-eventlistener (using jQuery) which checks if the scrollposition is reached and then do some action.

window.addEventListener('scroll', function(e) {
        //change color

posted this

Have an answer?


Please login first before posting an answer.