js控制滚动条示例
2013-08-01 13:21
197 查看
<html>
<head>
<script type="text/javascript">
var currentPosition,timer,timer1;
function GoTop(){
timer=setInterval("runToTop()",1);
}
function GoButtom(){
//alert(document.body.scrollHeight);
timer1=setInterval("runToButtom()",1);
}
function runToTop(){
currentPosition=document.documentElement.scrollTop || document.body.scrollTop;
currentPosition-=10;
if(currentPosition>0)
{
window.scrollTo(0,currentPosition);
}
else
{
window.scrollTo(0,0);
clearInterval(timer);
alert("over_top");
}
}
function runToButtom(){
currentPosition=document.documentElement.scrollTop || document.body.scrollTop;
currentPosition+=10;
var topheight=document.body.scrollHeight-document.body.clientHeight;
//alert(currentPosition+"---"+topheight);
if(currentPosition<topheight)
{
window.scrollTo(0,currentPosition);
}
else
{
window.scrollTo(0,topheight);
clearInterval(timer1);
alert("over_buttom");
}
}
</script>
<style type="text/css">
</style>
</head>
<body>
<div style="height:1000px;text-align:center;font-size:200px;font-weight:bold;">饭</div>
<div style="height:1000px;text-align:center;font-size:200px;font-weight:bold;">吃</div>
<div style="height:1000px;text-align:center;font-size:200px;font-weight:bold;">家</div>
<div style="height:1000px;text-align:center;font-size:200px;font-weight:bold;">回</div>
<div style="height:1000px;text-align:center;font-size:200px;font-weight:bold;">你</div>
<div style="height:1000px;text-align:center;font-size:200px;font-weight:bold;">带</div>
<div id="back-up" onclick="GoTop()" style="border:1px solid red;height:100px;width:15px;position:fixed;cursor:pointer;right:10px;bottom:30px;">返回顶部</div>
<script>
GoButtom();
</script>
</body>
</html>
<head>
<script type="text/javascript">
var currentPosition,timer,timer1;
function GoTop(){
timer=setInterval("runToTop()",1);
}
function GoButtom(){
//alert(document.body.scrollHeight);
timer1=setInterval("runToButtom()",1);
}
function runToTop(){
currentPosition=document.documentElement.scrollTop || document.body.scrollTop;
currentPosition-=10;
if(currentPosition>0)
{
window.scrollTo(0,currentPosition);
}
else
{
window.scrollTo(0,0);
clearInterval(timer);
alert("over_top");
}
}
function runToButtom(){
currentPosition=document.documentElement.scrollTop || document.body.scrollTop;
currentPosition+=10;
var topheight=document.body.scrollHeight-document.body.clientHeight;
//alert(currentPosition+"---"+topheight);
if(currentPosition<topheight)
{
window.scrollTo(0,currentPosition);
}
else
{
window.scrollTo(0,topheight);
clearInterval(timer1);
alert("over_buttom");
}
}
</script>
<style type="text/css">
</style>
</head>
<body>
<div style="height:1000px;text-align:center;font-size:200px;font-weight:bold;">饭</div>
<div style="height:1000px;text-align:center;font-size:200px;font-weight:bold;">吃</div>
<div style="height:1000px;text-align:center;font-size:200px;font-weight:bold;">家</div>
<div style="height:1000px;text-align:center;font-size:200px;font-weight:bold;">回</div>
<div style="height:1000px;text-align:center;font-size:200px;font-weight:bold;">你</div>
<div style="height:1000px;text-align:center;font-size:200px;font-weight:bold;">带</div>
<div id="back-up" onclick="GoTop()" style="border:1px solid red;height:100px;width:15px;position:fixed;cursor:pointer;right:10px;bottom:30px;">返回顶部</div>
<script>
GoButtom();
</script>
</body>
</html>
相关文章推荐
- js控制浏览器全屏示例代码
- 第十八节:JS控制网页内嵌滚动条的滚动
- js控制frameSet示例
- JS和JQUERY获取页面大小,滚动条位置,元素位置(示例代码)
- JS控制滚动条的位置
- Ferris这个教程学习笔记:js示例1:控制div属性
- js 上下左右键控制焦点(示例代码)
- js控制滚动条
- JS控制滚动条滚动的位置
- JS控制滚动条 —— 进度条的简单制作
- Ferris这个教程学习笔记:js示例1.1:控制div属性
- 利用JS来控制键盘的上下左右键(示例代码)
- python 通过js控制滚动条拉取全文 通过psutil获取pid窗口句柄,通过win32gui使程序窗口前置 通过autopy实现右键菜单和另存为操作
- js控制横向滚动条居中,鼠标在页面中的坐标
- JS控制滚动条放在最下与关闭窗体不提示信息
- JS 实现自定义滚动条 实现透明度控制和滚动条
- IE6与IE7,8下ifame中用JS控制滚动条的问题
- js控制”回到顶部“按钮滚动一屏后再显示和滚动条平滑滚动
- JS判断滚动条到达页面底部示例