$(function(){ var setGotop = function(){ var wh = getScrollPosition(); var maxH = $('body').height()-$('#footer').height() - $('#side').height() - 100; if(wh > 285){ $("#gotop").css("display","block"); if( wh < maxH){ $("#side").animate({"top":wh-270},{duration:0,queue:false}); } }else{ $("#gotop").css("display","none"); $("#side").animate({"top":0},{duration:0,queue:false}) } } function getScrollPosition() { return (document.documentElement.scrollTop || document.body.scrollTop); } $("#side").append('