回到顶部按钮js

jQuery(document).ready(function($) {
   $("<div id='toTop'><img src='/plugin/common/toTop/1.png'></div>").appendTo('body');
   $("#toTop").css({
      width: '50px',
      height: '50px',
      bottom:'100px',
      right:'15px',
      position:'fixed',
      cursor:'pointer',
      zIndex:'999999',
   });
   if($(this).scrollTop()==0){
      $("#toTop").hide();
   }
   $(window).scroll(function(event) {
      /* Act on the event */
      if($(this).scrollTop()==0){
         $("#toTop").hide();
      }
      if($(this).scrollTop()!=0){
         $("#toTop").show();
      }
   });
   $("#toTop").click(function(event) {
      /* Act on the event */
      $("html,body").animate({
         scrollTop:"0px"},
         800
         )
   });
});

猜你喜欢

转载自blog.csdn.net/weixin_39717076/article/details/81385936