RSS
热门关键字:  css  jquery  select input  asp jquery  用户注册
当前位置 :| 主页>JQuery插件>

jquery 实现 ScrollTo

来源: 作者: 时间:2008-10-26 Tag: 点击:

废话不多说 代码在下面,有不明白的去论坛发帖子去

 

jQuery.fn.ScrollTo = function(s) {
 o = jQuery.speed(s);
 return this.each(function(){
  new jQuery.fx.ScrollTo(this, o);
 });
};

jQuery.fx.ScrollTo = function (e, o)
{
 var z = this;
 z.o = o;
 z.e = e;
 z.p = jQuery.getPos(e);
 z.s = jQuery.getScroll();
 z.clear = function(){clearInterval(z.timer);z.timer=null};
 z.t=(new Date).getTime();
 z.step = function(){
  var t = (new Date).getTime();
  var p = (t - z.t) / z.o.duration;
  if (t >= z.o.duration+z.t) {
   z.clear();
   setTimeout(function(){z.scroll(z.p.y, z.p.x)},13);
  } else {
   st = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.y-z.s.t) + z.s.t;
   sl = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.x-z.s.l) + z.s.l;
   z.scroll(st, sl);
  }
 };
 z.scroll = function (t, l){window.scrollTo(l, t)};
 z.timer=setInterval(function(){z.step();},13);
};


最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册