Cut and paste snippet for adding a class to body if the page has been scrolled.

Useful for shrinking the menu on scroll, hiding things etc.
<pre class="lang:js decode:true">var $body = $('body'),
    last_known_scroll_position = 0,
    isScrolling = false;

function scrollUpdate(scroll_pos) {
    if ( scroll_pos === 0 ) {
        $body.removeClass('is-scrolling');
    } else {
        $body.addClass('is-scrolling');
    }
}

window.addEventListener('scroll', function(e) {
    last_known_scroll_position = window.scrollY;
    
    if (!isScrolling) {
        window.requestAnimationFrame(function() {
            scrollUpdate(last_known_scroll_position);
            isScrolling = false;
        });
        isScrolling = true;
    }
});
</pre>