Make the background of the navigation bar to change when scrolling

1901 views javascript
1

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

10

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) {
    if(window.scrollY>500)
    { 
        //change color
    }
})

posted this

Have an answer?

JD

Please login first before posting an answer.