var scrAlpha = 0; $(document).ready(function(){ $("#totop").click(function(){ $( 'html, body' ).animate({ scrollTop:0},500); //$( 'html, body' ).animate({scrollTop: $('#footer').offset().top},1000); }) $("#totop").mouseover(function(){ $("#totop").fadeTo(200,1); }) $("#totop").mouseout(function(){ $("#totop").fadeTo(200,scrAlpha); }) $(window).scroll(function(){ var scrTop = $(document).scrollTop(); var winHeight = $(window).height(); var docHeight = $(document).height(); if(scrTop > winHeight) { scrTop = scrTop - winHeight; docHeight = docHeight - winHeight * 2; scrAlpha = Math.round((scrTop / docHeight) * 10) / 10; } //$(".qqq").text(scrTop+"+"+winHeight+"+"+scrAlpha); $("#totop").css("opacity",scrAlpha); }); $("#sbtn").click(function(){ if($("#shareitem").hide()) { $("#shareitem").show(); } else{ $("#shareitem").hide(); } }); });