var hasBeenTrigged = false; $(window).scroll(function() { if ($(this).scrollTop() >= 150 && !hasBeenTrigged) { // if scroll is greater/equal then 100 and hasBeenTrigged is set to false. $('body').addClass('scrolling'); hasBeenTrigged = true; } if ($(this).scrollTop() < 150 && $('body').hasClass('scrolling')) { // if scroll is greater/equal then 100 and hasBeenTrigged is set to false. $('body').removeClass('scrolling'); hasBeenTrigged = false; } });