javascript 回到顶部 动画效果
2017-05-04 11:43
417 查看
上代码:
<!DOCTYPE html> <html> <head> <meta content="测试demo" name="Keywords"> <meta content="测试demo" name="Description"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> <title>js原生回到顶部</title> </head> <body style="width:100%;height:2000px"> <div style="position: fixed;bottom: 50px;right: 10%;" id="$backtotop">按钮</div> <script> !(function () { var Animate = function (dom) { this.startTime = 0; this.startPos = 0; this.endPos = 0; this.duration = null; if (!this.start) { Animate.prototype.start = function (endPos, duration) { this.startTime = +new Date; this.startPos = document.body.scrollTop; this.endPos = 0; this.duration = duration; var self = this; var timeId = setInterval(function () { if (self.step() === false) { clearInterval(timeId); } }, 19); }; Animate.prototype.step = function () { var t = +new Date; if (t >= this.startTime + this.duration) { this.update(this.endPos); return false; } var pos = function (t, b, c, d) { return c * t / d + b; }; this.update(pos(t - this.startTime, this.startPos, this.endPos - this.startPos, this.duration)); }; Animate.prototype.update = function (pos) { document.body.scrollTop = pos; }; }; }; document.getElementById("$backtotop").onclick = function () { var animate = new Animate(); animate.start(0, 300); }; })(); </script> </body> </html>
相关文章推荐
- javascript 回到顶部效果的实现代码
- jQuery实现带有动画效果的回到顶部和底部代码
- JavaScript回到顶部的滑动效果实现
- javascript 回到顶部效果的实现代码
- 使用JavaScript实现回到顶部效果
- javascript回到顶部滑动效果及点击导航滑动到相应热点的效果
- Javascript 实现回到顶部效果
- 用Javascript实现回到顶部效果
- JS实现回到页面顶部动画效果 2016.03.23
- iOS开发- 点击通知栏回到顶部的动画效果
- jQuery实现带有动画效果的回到顶部和底部代码
- JS实现回到页面顶部动画效果的简单实例
- javascript 特效实现(2)——回到顶部效果
- 一个回到顶部的插件topjs,支持自定义,使用简单,带动画效果
- 使用JavaScript实现回到顶部效果
- 基于JavaScript实现回到页面顶部动画代码
- 用javascript实现回到顶部效果
- javascript 回到顶部的效果实现
- 用jQuery为跳转链接锚点添加平滑滚动动画效果(如回到顶部
- 回到顶部缓动效果代码 --- tween动画函数库