$(window).on("scroll", function() { var fromTop = $(document).scrollTop(); $('#site-header').toggleClass("sticky", (fromTop >= 190)); }); }); })(jQuery);