回到顶部jquery特效

孤人 提交于 2019-11-28 03:56:50
  <!DOCTYPE html>
  <html lang="en">
  <head>
  <meta charset="UTF-8">
  <title>Document</title>
  <script src="jquery.js"></script>
  <style>
  button{
  position: fixed;right: 10px;bottom:20px;display: none;
  }
  </style>
  </head>
  <body style="height:2000px;">
  <button>回到顶部</button>
   
  <script>
  $(function(){
  $(window).scroll(function(){
  var t = $('html,body').scrollTop();
  if(t>200){
  $('button').show();
  }else{
  $('button').hide();
  }
  })
  $('button').click(function(){
  $('body,html').animate({
  scrollTop:0
  },300)
  })
  })
  </script>
  </body>
  </html>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!