var $document = $(document), $element = $('.fixed-menu'), className = 'hasScrolled'; $document.scroll(function() { if ($document.scrollTop() >= 100) { $element.addClass(className); } else { $element.removeClass(className); } });