Now the element is, say, 200px from the top. How to make it so that after 210px is scrolled down, then the element will be given certain styles?

    1 answer 1

    $(document).scroll(function() { if ( $(this).scrollTop() >= 410 ) { $('#myBlock').css( ... ) } }); 
    • to the note: it is recommended to wrap such functions in such a way that its call does not occur too often, like _.throttle - Specter
    • Naturally, everything should be within reasonable limits and interpreted by the tasks. For example, in this task I would not use _.throttle. It is enough to set the flag for setting the required styles and check the height of the document when scrolling and whether the class is set (so that if () would work only 1 time for the specified interval). Since _.throttle will do a similar task with as much blood as possible (using the + setTimeout flags in the same way) - iKuzko
    • fully agree, just could not find a clearer example explaining the essence of the thought - Specter