js滚动到顶部底部代码
- <!DOCTYPE HTML>
- <html>
- <head>
- <meta charset=UTF-8>
- <title>SCROLL</title>
- <style type="text/css">
- </style>
- <script type="text/javascript">
- var goToWhere = function (where)
- {
- var me = this;
- me.site = [];
- me.sleep = me.sleep ? me.sleep : 16;
- me.fx = me.fx ? me.fx : 6;
- clearInterval (me.interval);
- var dh = document.documentElement.scrollHeight || document.body.scrollHeight;
- var height = !!where ? dh : 0;
- me.interval = setInterval (function ()
- {
- var top = document.documentElement.scrollTop || document.body.scrollTop;
- var speed = (height - top) / me.fx;
- if (speed === me.site[0])
- {
- window.scrollTo (0, height);
- clearInterval (me.interval);
- }
- window.scrollBy (0, speed);
- me.site.unshift (speed);
- }, me.sleep);
- };
- </script>
- </head>
- <body>
- <div style="height: 1000px; text-align: center; font-size: 200px; font-weight: bold;">5</div>
- <div style="height: 1000px; text-align: center; font-size: 200px; font-weight: bold;">4</div>
- <div style="height: 1000px; text-align: center; font-size: 200px; font-weight: bold;">3</div>
- <div style="height: 1000px; text-align: center; font-size: 200px; font-weight: bold;">2</div>
- <div style="height: 1000px; text-align: center; font-size: 200px; font-weight: bold;">1</div>
- <div style="height: 1000px; text-align: center; font-size: 200px; font-weight: bold;">0</div>
- <div onclick="goToWhere(0)"
- style="border: 1px solid red; height: 100px; width: 15px; position: fixed; cursor: pointer; right: 10px; bottom: 150px;">返回顶部</div>
- <div onclick="goToWhere(1)"
- style="border: 1px solid red; height: 100px; width: 15px; position: fixed; cursor: pointer; right: 10px; bottom: 30px;">返回底部</div>
- </body>
- </html>
js滚动到顶部底部代码的更多相关文章
- js平滑滚动到顶部,底部,指定地方
[原文链接] 采用锚点进行页面中的跳转的确很方便,但是要想增加网页的效果,可以使用jquery中的animate,实现滚动的一个动作,慢慢的滚动到你想跳转到的位置,从而看起来会非常高大上. [示例演示 ...
- selenium webdriver——JS滚动到最底部
JS控制滚动条的位置: window.scrollTo(x,y); 竖向滚动条置顶 window.scrollTo(0,0); 竖向滚动条置底 window.scrollTo(0,document.b ...
- JQuery - 点击,滚动回到顶部 / 底部刷新回到顶部
if ($(document).scrollTop() != 0) { //刷新之后,回到顶部 $('body,html').animate({ scrollTop: 0 }, 500); }
- [js常用]页面滚动的顶部,指定位置或底部,平滑滚动
js平滑滚动到顶部.底部.指定地方 <!DOCTYPE html> <html lang="en"> <head> <meta chars ...
- 当滚动条滚动到页面底部自动加载增加内容的js代码
这篇文章主要介绍了如何使用javscript实现滚动条滚动到页面底部自动加载增加页面内容,需要的朋友可以参考下..1,注册页面滚动事件,window.onscroll = function(){ }; ...
- js获取滚动条距离浏览器顶部,底部的高度,兼容ie和firefox
做web开发经常会碰到需要获取浏览器的滚动条与顶部和底部的距离,然后做相应的处理动作.下面作者就如何通过js来获取浏览器滚动条距离浏览器顶部和底部的高度做一下分享,这个是同时兼容ie和firefox的 ...
- ListView(1)几个重要属性,关闭滚动到顶部,底部的动画,item之间的分割线,背景等
见表: android:stackFromBottom="true" 设置该属性之后你做好的列表就会显示你列表的最下面,值为true和false android:transcrip ...
- vue.js学习之 如何在better-scroll加载完成后,自动滚动到最底部
首先我们需要使用scrollTo这个方法: scrollTo(x, y, time, easing) 参数: {Number} x 横轴坐标(单位 px) {Number} y 纵轴坐标(单位 px) ...
- 页面滚动事件和利用JS实现回到顶部效果
页面滚动 事件:window.onscroll, 获得页面滚动位置:document.body.scrollTop: HTML代码: 这里注意此处逻辑,大于500就显示,否则就隐藏,还有注意如果变量名 ...
随机推荐
- VC连接SQLite3的方法(MFC封装类)
SQLite,是一款轻型的数据库,是遵守ACID的关联式数据库管理系统,支持跨平台,操作简单,能够使用很多语言直接创建数据库.官方网站:www.sqlite.org 在VC环境下编写连接SQLite的 ...
- [CSP-S模拟测试]:影子(并查集+LCA)
题目描述 一个人有很多的影子,新的旧的,他们不断消失重来.学者的影子在他苍白色的精神图景里成为了$n$个黑色的点,他们伸长的触手交叉形成了一颗黑色的树.假使每个影子点拥有一个权值$d_i$,黑色的树边 ...
- mysql全家桶(二)数据操作
一.数据操作1.增#新增insert into 表名(字段列表) values(值列表);INSERT INTO table_name ( field1, field2,...fieldN ) VAL ...
- (转)使用OpenGL显示图像(五)添加移动
添加移动 编写:jdneo - 原文:http://developer.android.com/training/graphics/opengl/motion.html 转:http://hukai. ...
- ng-repeat高级用法
ng-repeat高级用法: 遍历数组: <li ng-repeat="item in array">{{item}}</li> 遍历对象: key:对象的 ...
- 2019牛客多校第⑨场E All men are brothers(并查集+组合数学)
原题:https://ac.nowcoder.com/acm/contest/889/E 思路: 做并查集,维护每个集合大小,初始化操作前的总方案数,每次合并两个集合时减少的数量=合并的两个集合大小相 ...
- 点读系列《jmeter官方用户手册》
官网:http://jmeter.apache.org/usermanual/ 说明:十八元件.十九属性.二十函数,涉及清单内容暂未仔细阅读,个人觉得一是仅供使用参考,二是适合单独写文章来解读 一.让 ...
- Spring Data JPA one to one 共享主键关联
/** * Created by xiezhiyan on 17-9-13. */@Entitypublic class Token { @Id @Column(name = "store_ ...
- Oracle多种表连接方式
1. 内连接(自然连接) 2. 外连接 (1)左外连接 (左边的表不加限制) (2)右外连接(右边的表不加限制) (3)全外连接(左右两表都不加限制) 3. 自连接(同一张表内的连接) SQL的标准语 ...
- 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 ...