var footerjs = { showtop : function(){ if ($(document).scrolltop() < 600) { $("#gotop").hide(); }else{ $("#gotop").show(); } } }; $(document).scroll(function(){ footerjs.showtop(); }); $(document).ready(function(){ footerjs.showtop(); $("#gotop-nei img").click(function(){ $('html,body').animate({scrolltop:'0px'}); }); });