G
G
Greeg Zagrelov2020-05-02 10:44:19
css
Greeg Zagrelov, 2020-05-02 10:44:19

How to change header color on page scroll?

How to make header color change on page scroll in pure JS?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
eugenedrvnk, 2020-05-02
@OldSchool1705

If you need to change the color of the header after passing a certain mark, then something like:

document.addEventListener('resize', () => {
  if (window.scrollY > 200 && heder.style.color != 'red') {
    header.style.color = 'red'
  } else if (header.style.color == 'red') header.style.color = 'auto'
})

And if you need the color to change smoothly as you scroll, then you should probably turn to the ScrollMagic plugin.

C
catherinetr, 2020-05-02
@catherinetr

function nameFunct() {
    var hScroll = 0;
    var hWindow = jQuery(window).height(); 
    
    jQuery(window).scroll(function() {
        hScroll = jQuery(this).scrollTop() + hWindow;
        
        if (jQuery(this).scrollTop() >= 220) {
            
        } else {
           
        }
    });
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question