JQuery返回顶部

为了兼容谷歌和火狐,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();
      }
  })

猜你喜欢

转载自www.cnblogs.com/xiaonangua/p/9176593.html