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就显示,否则就隐藏,还有注意如果变量名 ...
随机推荐
- Angular项目中引入jQuery
npm install --save jquery npm install @types/jquery --save 在对应的组件中引入 import * as $ from "jquery ...
- prototype、proto和constructor 关系
记录: 1.构造函数:如下,Foo()就是一个构造函数 function Foo(){} 2.prototype:每一个构造函数都有一个属性叫prototype,相当于一个指针,指向它的原型对象 Fo ...
- 【已转移】【缓存与性能优化】一篇文章搞掂:Redis
本文篇幅较长,建议合理利用右上角目录进行查看(如果没有目录请刷新). 一.什么是Redis 全称: Remote Dictionary Server 远程字典服务器 实质: 一个缓存结构服务器或数据结 ...
- 左闭右开线段树 2019牛客多校(第七场)E_Find the median(点代表区间
目录 题意 一种解析 AC_Code @(2019第七场牛客 E_Find the median 左闭右开线段树) 题意 链接:here 我理解的题意就是:初始序列为空,有\(n(400000)\)次 ...
- mybatis原理与设计模式-日志模块- 适配器模式
在讲设计模式之前,得先知道java程序设计中得六大原则,才能更好得理解我们得系统为什么需要设计模式 1 单一职责原则 一个类只负责一种职责,只有这种职责的改变会导致这个类的变更.绕口一点的正统说法:不 ...
- Python机器学习及分析工具:Scikit-learn篇
https://www.jianshu.com/p/e0844e7cdba5 https://sklearn.apachecn.org/docs/0.21.3/62.html 中文文档
- 政府网站综合防护系统(网防G01)
政府网站综合防护系统,简称“网防G01”,是首款专门针对政府网站及服务器等关键信息基础资源进行综合防护的产品,由公安部第一研究所和计算机病毒防治技术国家工程实验室(北京)研发. 网防G01的架构 由服 ...
- 如何在原生Android项目里嵌入Cordova
背景: 这段时间在维护一个Cordova混合项目,以前稍微接触过Cordova,也写过简单的纯纯的Cordova的Demo,但是没有尝试过混合原生的Cordova. 在接到项目后比较了一下项目架构和C ...
- 以您熟悉的编程语言为例完成一个hello/hi的简单的网络聊天程序
Socket通常也称作"套接字",用于描述IP地址和端口,是一个通信链的句柄,可以用来实现不同虚拟机或不同计算机之间的通信,应用程序通常通过"套接字"向网络发出 ...
- linux Cron 定时任务(centos 7.2 测试可用)
1.Cron(学习笔记) 计划任务,是任务在约定的时间执行已经计划好的工作. 格式如下 Seconds Minutes Hours DayofMonth Month DayofWeek Year ...