js滾動條回到頂部的代碼
更新時間:2011年12月06日 22:19:13 作者:
js滾動條回到頂部的代碼,里面的js代碼比較簡單,很適合學習。
雖然平滑性處理的不好,但非常適合學習
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript">
//怎么獲取網(wǎng)頁的高度 讓頁面一出來就滾動條在最底端
function myScroll()
{
//前邊是獲取chrome等一般瀏覽器 如果獲取不到就是ie了 就用ie的辦法獲取
var x=document.body.scrollTop||document.documentElement.scrollTop;
var timer=setInterval(function(){
x=x-100;
if(x<100)
{
x=0;
window.scrollTo(x,x);
clearInterval(timer);
}
window.scrollTo(x,x);
},"250");
}
</script>
<title></title>
</head>
<body id="bd">
<div>
<div style="height:1000px;">初始化</div>
<div style="height:1000px">
<div
style="position:fixed;right:10px;bottom:50px;width:20px;height:70px;background-color:red;cursor:hand;"
onclick="myScroll()">返回頂端</div>
</div>
</body>
</html>
復制代碼 代碼如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript">
//怎么獲取網(wǎng)頁的高度 讓頁面一出來就滾動條在最底端
function myScroll()
{
//前邊是獲取chrome等一般瀏覽器 如果獲取不到就是ie了 就用ie的辦法獲取
var x=document.body.scrollTop||document.documentElement.scrollTop;
var timer=setInterval(function(){
x=x-100;
if(x<100)
{
x=0;
window.scrollTo(x,x);
clearInterval(timer);
}
window.scrollTo(x,x);
},"250");
}
</script>
<title></title>
</head>
<body id="bd">
<div>
<div style="height:1000px;">初始化</div>
<div style="height:1000px">
<div
style="position:fixed;right:10px;bottom:50px;width:20px;height:70px;background-color:red;cursor:hand;"
onclick="myScroll()">返回頂端</div>
</div>
</body>
</html>
相關(guān)文章
javascript實現(xiàn)動態(tài)增加刪除表格行(兼容IE/FF)
javascript實現(xiàn)動態(tài)增加刪除表格行(兼容IE/FF)...2007-04-04
js動態(tài)創(chuàng)建上傳表單通過iframe模擬Ajax實現(xiàn)無刷新
這篇文章主要介紹了js動態(tài)創(chuàng)建上傳表單通過iframe模擬Ajax無刷新的具體實現(xiàn),需要的朋友可以參考下2014-02-02
BootStrap智能表單實戰(zhàn)系列(七)驗證的支持
這篇文章主要介紹了BootStrap智能表單實戰(zhàn)系列(七)驗證的支持 ,凡是涉及到用戶編輯信息然后保存的頁面,都涉及到一個數(shù)據(jù)是否符合要求的檢查,需要客服端和服務器端的校驗的問題,本文介紹非常詳細,具有參考價值,需要的朋友可以參考下2016-06-06
Javascript在IE和Firefox瀏覽器常見兼容性問題總結(jié)
這篇文章主要介紹了Javascript在IE和Firefox瀏覽器常見兼容性問題,結(jié)合實例形式總結(jié)分析了javascript在IE與Firefox瀏覽器中常見的各種兼容性問題與相應的解決方法,需要的朋友可以參考下2016-08-08

