Difference between revisions of "Template:Team:CHINA CD UESTC/basicjs"

(Created page with "function gotoTop(acceleration,stime) { acceleration = acceleration || 0.1; stime = stime || 10; var x1 = 0; var y1 = 0; var x2 = 0; var y2 = 0; var x3 = 0...")
 
Line 1: Line 1:
function gotoTop(acceleration,stime) {
+
$(function(){
  acceleration = acceleration || 0.1;
+
$(window).scroll(function() {
  stime = stime || 10;
+
if($(window).scrollTop() >= 100){ //????????????ֵʱ???????С??~
  var x1 = 0;
+
$('.actGotop').fadeIn(300); //?????????䣬ԽС????????
  var y1 = 0;
+
}else{    
  var x2 = 0;
+
$('.actGotop').fadeOut(300); //??????????䣬ԽС?ʧ?????
  var y2 = 0;
+
}  
  var x3 = 0;
+
});
  var y3 = 0;
+
$('.actGotop').click(function(){$('html,body').animate({scrollTop: '0px'}, 800);}); //??????ͣ????䣬ԽС?ʧ?????
  if (document.documentElement) {
+
});
      x1 = document.documentElement.scrollLeft || 0;
+
</script>
      y1 = document.documentElement.scrollTop || 0;
+
  }
+
  if (document.body) {
+
      x2 = document.body.scrollLeft || 0;
+
      y2 = document.body.scrollTop || 0;
+
  }
+
   var x3 = window.scrollX || 0;
+
  var y3 = window.scrollY || 0;
+
+
  var x = Math.max(x1, Math.max(x2, x3));
+
  var y = Math.max(y1, Math.max(y2, y3));
+
   
+
  var speeding = 1 + acceleration;
+
  window.scrollTo(Math.floor(x / speeding), Math.floor(y / speeding));
+
+
  if(x > 0 || y > 0) {
+
      var run = "gotoTop(" + acceleration + ", " + stime + ")";
+
      window.setTimeout(run, stime);
+
  }
+
}
+

Revision as of 14:00, 15 September 2015

$(function(){ $(window).scroll(function() { if($(window).scrollTop() >= 100){ //????????????ֵʱ???????С??~ $('.actGotop').fadeIn(300); //?????????䣬ԽС???????? }else{ $('.actGotop').fadeOut(300); //??????????䣬ԽС?ʧ????? } }); $('.actGotop').click(function(){$('html,body').animate({scrollTop: '0px'}, 800);}); //??????ͣ????䣬ԽС?ʧ????? }); </script>