function intval(v) {
v = parseInt(v);
return isNaN(v) ? 0 : v;
}
function getPos(e) {
var l = 0;
var t = 0;
var w = intval(e.style.width);
var h = intval(e.style.height);
var wb = e.offsetWidth;
var hb = 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
};
}
function getScroll() {
var t, 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;
} else if (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
};
}
function scroller(el, duration) {
if (typeof el != "object") {
el = document.getElementById(el);
}
if (!el) return;
var z = this;
z.el = el;
z.p = getPos(el);
z.s = getScroll();
z.clear = function() {
window.clearInterval(z.timer);
z.timer = null
};
z.t = (new Date).getTime();
z.step = function() {
var t = (new Date).getTime();
var p = (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);
}

调用方式 :

onclick="scroller('igbook', 200)"

最新文章

  1. 浅谈CommandBehavior枚举的独特之处
  2. 初接触BurpLoader工具
  3. Oracle函数大全之转换函数
  4. [大牛翻译系列]Hadoop(5)MapReduce 排序:次排序(Secondary sort)
  5. 《深入Java虚拟机学习笔记》- 第3章 安全
  6. WebService学习笔记
  7. struts中如何将前台的值能在action中获取到
  8. 《vi中的替换艺术》-linux命令五分钟系列之十一
  9. .NET 元数据
  10. 【iOS】7.4 定位服务->3.1 地图框架MapKit 功能1:地图展示
  11. 零基础的人该怎么学习JAVA
  12. Hyperledger Fabric Model——超级账本组成模型
  13. H5WebSocket前后台代码
  14. Ubuntu 安装LAMP
  15. 直径上的乱搞 bzoj1999求树直径上的结点+单调队列,bzoj1912负权树求直径+求直径边
  16. Codeforces909D Colorful Points(缩点)
  17. 深度学习课程笔记(十)Q-learning (Continuous Action)
  18. 第5月第13天 node cnpm安装 babel
  19. Solr增删改查索引
  20. jzoj2941

热门文章

  1. C 命令行参数
  2. 【Excle数据透视】如何创建一个数据透视表
  3. python 中给文件加锁——fcntl模块
  4. linux下robotframework执行测试用例的几种方法
  5. Snubber电路
  6. 获取input光标的x和y轴
  7. 黑名单机制来临,你的应用还好么?Android P DP2最新兼容性报告出炉
  8. 常用yum命令小结
  9. java中的 equals + hashCode
  10. GS与网络打交道