$(window).scroll(function () { var scrollTop = $(window).scrollTop(); if (scrollTop > 50){ $('.all').addClass("fixednav").stop().animate({ top: 0 }, 300); $('#header').css({"z-index":1000}); }else{ $('.all').css({"top":'-100px'}).removeClass("fixednav").stop ().animate({ top: "0px" }, 300); $('#header').css({"z-index":99}); } });