There is such a html:

<header> </header> <section class="welcome"> <h1>на протяжении 30 лет занимается строительством домов по фахверк-технологии </h1> </section> 

It is necessary that, as soon as a block of section appears in the field of view of a header, the class changes. Now I have this code:

 function scrollMe() { $(window).scroll(function () { //var refTarget = $('.navigation__list a'); if ($(window).scrollTop() < '600') { $('header').addClass('header__wrap-scrolled'); } 

But this does not work, because the distance is constantly changing and it appears early, then late. There is a solution?

    1 answer 1

    You can find out the position of a section like this:

     $('section').offset().top 

    and compare with $(window).scrollTop()