$(document).ready(function() { $("#cmTopScroll").click(function (){ $("html, body").animate({scrollTop:0}, 200); }); $(window).scroll(function (){ var top = $(document).scrollTop(); if(top > 300){ $("#cmTopScroll").stop().animate({"bottom":40}, 250); }else{ $("#cmTopScroll").stop().animate({"bottom":-200}, 250); } }); });