Javascript 实现锚点(Anchor)间平滑跳转
2013-10-11 15:11
441 查看
(function($){ $.fn.scroller=function(options){ vardefaultVal={ duration:500 }; varobj=$.extend({},defaultVal,options); varel=options.el; varduration=options.duration; returnthis.each(function(){ if(typeofel!='object'){ el=document.getElementById(el); } if(!el)return; varz=this; z.el=el; z.p=getPos(el); z.s=getScroll(); z.clear=function(){ window.clearInterval(z.timer);z.timer=null }; z.t=(newDate).getTime(); z.step=function(){ vart=(newDate).getTime(); varp=(t-z.t)/duration; if(t>=duration+z.t){ z.clear(); window.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=window.setInterval(function(){z.step();},13); }); }; functionintval(v) { v=parseInt(v); returnisNaN(v)?0:v; } //获取元素信息 functiongetPos(e) { varl=0; vart=0; varw=intval(e.style.width); varh=intval(e.style.height); varwb=e.offsetWidth; varhb=e.offsetHeight; while(e.offsetParent){ l+=e.offsetLeft+(e.currentStyle?intval(e.currentStyle.borderLeftWidth):0); t+=e.offsetTop+(e.currentStyle?intval(e.currentStyle.borderTopWidth):0); e=e.offsetParent; } l+=e.offsetLeft+(e.currentStyle?intval(e.currentStyle.borderLeftWidth):0); t+=e.offsetTop+(e.currentStyle?intval(e.currentStyle.borderTopWidth):0); return{x:l,y:t,w:w,h:h,wb:wb,hb:hb}; } //获取滚动条信息 functiongetScroll() { vart,l,w,h; if(document.documentElement&&document.documentElement.scrollTop){ t=document.documentElement.scrollTop; l=document.documentElement.scrollLeft; w=document.documentElement.scrollWidth; h=document.documentElement.scrollHeight; }elseif(document.body){ t=document.body.scrollTop; l=document.body.scrollLeft; w=document.body.scrollWidth; h=document.body.scrollHeight; } return{t:t,l:l,w:w,h:h}; } })(jQuery) $(function(){ $('#goto').click(function(){ $(this).scroller( { el:'t1', duration:1000 } ); }); })
相关文章推荐
- 用Javascript实现锚点(Anchor)间平滑跳转
- 用 Javascript 实现锚点(Anchor)间平滑跳转
- 用 Javascript 实现锚点(Anchor)间平滑跳转
- 用 Javascript 实现锚点(Anchor)间平滑跳转 【转载】
- 用Javascript实现锚点(Anchor)间平滑跳转
- js实现平滑跳转到锚点(Anchor)
- jQuery实现页面内锚点平滑跳转特效的方法总结
- jQuery实现页面内锚点平滑跳转 滑动效果
- jQuery实现页面内锚点平滑跳转
- jQuery实现页面内锚点平滑跳转特效的方法总结
- 利用javascript 实现锚点间平滑移动
- jquery页内锚点平滑跳转实现代码
- jQuery实现页面内锚点平滑跳转
- jQuery实现页面内锚点平滑跳转特效的方法总结
- jquery实现页面内链接锚点跳转平滑滚动效果
- 利用javascript实现页面跳转的几种方法
- 【特效】锚点平滑跳转和偏移
- jQuery实现平滑滚动页面到指定锚点链接的方法
- JavaScript解决一个带验证的Form两个Submit事件(一个页面保持不动【AJAX实现】,一个页面提交并跳转)的场景
- javascript实现跳转菜单的具体方法