您现在的位置: 万盛学电脑网 >> 程序编程 >> 脚本专题 >> javascript >> 正文

jquery返回顶部代码

作者:佚名    责任编辑:admin    更新时间:2022-06-22

  分享一个jquery在返回顶部在代码:不依赖CSS

  $("body").append("

∧  

");

 

  var totop=$("#toTop");

  totop.bind({

  click:function(){

  $("html,body").animate({scrollTop:0},500)

  },

  mouseover:function(){

  $("#toTopTips").stop(false,true).fadeIn()

  $(this).css({"background-color":"#51B9FF"})

  },

  mouseout:function(){

  $("#toTopTips").css("display","none")

  $(this).css({"background-color":"#09F"})

  }

  })

  $(window).scroll(function(){

  if($.browser.msie && ($.browser.version == "6.0") && !$.support.style){//如果IE6

  totop.css({"top":($(window).scrollTop()+$(window).height()-100)+"px","position":"absolute"});

  }

  if($(window).scrollTop()<=50){

  totop.fadeOut();

  }else{

  totop.fadeIn();

  }

  });