$(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('
'); $("#gotop").click(function(){ $('html,body').animate({scrollTop: 0},500); }); if('http://' + location.hostname +'/' != window.location.href){ $(window).scroll(setGotop); $(window).resize(setGotop); } $("#gotop").hover(function() { $(this).addClass("over"); }, function() { $(this).removeClass("over"); }); // $("a[href^=#]").click(function(){ var Hash = $(this.hash); var HashOffset = $(Hash).offset().top; $("html,body").animate({ scrollTop: HashOffset }, 600); return false; }); // });