1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset=UTF-8>
  5. <title>SCROLL</title>
  6. <style type="text/css">
  7. </style>
  8. <script type="text/javascript">
  9. var goToWhere = function (where)
  10. {
  11. var me = this;
  12. me.site = [];
  13. me.sleep = me.sleep ? me.sleep : 16;
  14. me.fx = me.fx ? me.fx : 6;
  15. clearInterval (me.interval);
  16. var dh = document.documentElement.scrollHeight || document.body.scrollHeight;
  17. var height = !!where ? dh : 0;
  18. me.interval = setInterval (function ()
  19. {
  20. var top = document.documentElement.scrollTop || document.body.scrollTop;
  21. var speed = (height - top) / me.fx;
  22. if (speed === me.site[0])
  23. {
  24. window.scrollTo (0, height);
  25. clearInterval (me.interval);
  26. }
  27. window.scrollBy (0, speed);
  28. me.site.unshift (speed);
  29. }, me.sleep);
  30. };
  31. </script>
  32. </head>
  33. <body>
  34. <div style="height: 1000px; text-align: center; font-size: 200px; font-weight: bold;">5</div>
  35. <div style="height: 1000px; text-align: center; font-size: 200px; font-weight: bold;">4</div>
  36. <div style="height: 1000px; text-align: center; font-size: 200px; font-weight: bold;">3</div>
  37. <div style="height: 1000px; text-align: center; font-size: 200px; font-weight: bold;">2</div>
  38. <div style="height: 1000px; text-align: center; font-size: 200px; font-weight: bold;">1</div>
  39. <div style="height: 1000px; text-align: center; font-size: 200px; font-weight: bold;">0</div>
  40. <div  onclick="goToWhere(0)"
  41. style="border: 1px solid red; height: 100px; width: 15px; position: fixed; cursor: pointer; right: 10px; bottom: 150px;">返回顶部</div>
  42. <div  onclick="goToWhere(1)"
  43. style="border: 1px solid red; height: 100px; width: 15px; position: fixed; cursor: pointer; right: 10px; bottom: 30px;">返回底部</div>
  44. </body>
  45. </html>

js滚动到顶部底部代码的更多相关文章

  1. js平滑滚动到顶部,底部,指定地方

    [原文链接] 采用锚点进行页面中的跳转的确很方便,但是要想增加网页的效果,可以使用jquery中的animate,实现滚动的一个动作,慢慢的滚动到你想跳转到的位置,从而看起来会非常高大上. [示例演示 ...

  2. selenium webdriver——JS滚动到最底部

    JS控制滚动条的位置: window.scrollTo(x,y); 竖向滚动条置顶 window.scrollTo(0,0); 竖向滚动条置底 window.scrollTo(0,document.b ...

  3. JQuery - 点击,滚动回到顶部 / 底部刷新回到顶部

    if ($(document).scrollTop() != 0) { //刷新之后,回到顶部 $('body,html').animate({ scrollTop: 0 }, 500); }

  4. [js常用]页面滚动的顶部,指定位置或底部,平滑滚动

    js平滑滚动到顶部.底部.指定地方 <!DOCTYPE html> <html lang="en"> <head> <meta chars ...

  5. 当滚动条滚动到页面底部自动加载增加内容的js代码

    这篇文章主要介绍了如何使用javscript实现滚动条滚动到页面底部自动加载增加页面内容,需要的朋友可以参考下..1,注册页面滚动事件,window.onscroll = function(){ }; ...

  6. js获取滚动条距离浏览器顶部,底部的高度,兼容ie和firefox

    做web开发经常会碰到需要获取浏览器的滚动条与顶部和底部的距离,然后做相应的处理动作.下面作者就如何通过js来获取浏览器滚动条距离浏览器顶部和底部的高度做一下分享,这个是同时兼容ie和firefox的 ...

  7. ListView(1)几个重要属性,关闭滚动到顶部,底部的动画,item之间的分割线,背景等

    见表: android:stackFromBottom="true" 设置该属性之后你做好的列表就会显示你列表的最下面,值为true和false android:transcrip ...

  8. vue.js学习之 如何在better-scroll加载完成后,自动滚动到最底部

    首先我们需要使用scrollTo这个方法: scrollTo(x, y, time, easing) 参数: {Number} x 横轴坐标(单位 px) {Number} y 纵轴坐标(单位 px) ...

  9. 页面滚动事件和利用JS实现回到顶部效果

    页面滚动 事件:window.onscroll, 获得页面滚动位置:document.body.scrollTop: HTML代码: 这里注意此处逻辑,大于500就显示,否则就隐藏,还有注意如果变量名 ...

随机推荐

  1. VC连接SQLite3的方法(MFC封装类)

    SQLite,是一款轻型的数据库,是遵守ACID的关联式数据库管理系统,支持跨平台,操作简单,能够使用很多语言直接创建数据库.官方网站:www.sqlite.org 在VC环境下编写连接SQLite的 ...

  2. [CSP-S模拟测试]:影子(并查集+LCA)

    题目描述 一个人有很多的影子,新的旧的,他们不断消失重来.学者的影子在他苍白色的精神图景里成为了$n$个黑色的点,他们伸长的触手交叉形成了一颗黑色的树.假使每个影子点拥有一个权值$d_i$,黑色的树边 ...

  3. mysql全家桶(二)数据操作

    一.数据操作1.增#新增insert into 表名(字段列表) values(值列表);INSERT INTO table_name ( field1, field2,...fieldN ) VAL ...

  4. (转)使用OpenGL显示图像(五)添加移动

    添加移动 编写:jdneo - 原文:http://developer.android.com/training/graphics/opengl/motion.html 转:http://hukai. ...

  5. ng-repeat高级用法

    ng-repeat高级用法: 遍历数组: <li ng-repeat="item in array">{{item}}</li> 遍历对象: key:对象的 ...

  6. 2019牛客多校第⑨场E All men are brothers(并查集+组合数学)

    原题:https://ac.nowcoder.com/acm/contest/889/E 思路: 做并查集,维护每个集合大小,初始化操作前的总方案数,每次合并两个集合时减少的数量=合并的两个集合大小相 ...

  7. 点读系列《jmeter官方用户手册》

    官网:http://jmeter.apache.org/usermanual/ 说明:十八元件.十九属性.二十函数,涉及清单内容暂未仔细阅读,个人觉得一是仅供使用参考,二是适合单独写文章来解读 一.让 ...

  8. Spring Data JPA one to one 共享主键关联

    /** * Created by xiezhiyan on 17-9-13. */@Entitypublic class Token { @Id @Column(name = "store_ ...

  9. Oracle多种表连接方式

    1. 内连接(自然连接) 2. 外连接 (1)左外连接 (左边的表不加限制) (2)右外连接(右边的表不加限制) (3)全外连接(左右两表都不加限制) 3. 自连接(同一张表内的连接) SQL的标准语 ...

  10. 2018-8-9-win-消息

    title author date CreateTime categories win 消息 lindexi 2018-8-9 15:35:4 +0800 2018-2-13 17:23:3 +080 ...