function tbox(){ //h = $(window).height(); t = $(document).scrolltop(); if(t > 150){ $(".tbox").fadein(300); }else{ $(".tbox").fadeout(300); } } $(document).ready(function(e){ $("body").append('
'); tbox(); $("#gotop").click(function(){ $(document).scrolltop(0); }) }); $(window).scroll(function(e){ tbox(); })