为了兼容谷歌和火狐,body和html都要写(这是个坑)
$(".go-top").on('click',function(){ $('body,html').animate({scrollTop: 0},1000) }) //滑动到指定位置,开始显示图标 $(window).scroll(function(){ var top=$(this).scrollTop(); if(top>200){ $(".go-top").fadeIn(); }else{ $(".go-top").fadeOut(); } })