純文字版返回頂端的js代碼
更新時間:2013年08月01日 16:51:41 作者:
這篇文章介紹了純文字版返回頂端的js代碼,有需要的朋友可以參考一下
復(fù)制代碼 代碼如下:
<script language="javascript">
var goto_top_type = -1;
var goto_top_itv = 0;
function goto_top_timer() {
var y = goto_top_type == 1 ? document.documentElement.scrollTop
: document.body.scrollTop;
var moveby = 15;
y -= Math.ceil(y * moveby / 100);
if (y < 0) {
y = 0;
}
if (goto_top_type == 1) {
document.documentElement.scrollTop = y;
} else {
document.body.scrollTop = y;
}
if (y == 0) {
clearInterval(goto_top_itv);
goto_top_itv = 0;
}
}
function goto_top() {
if (goto_top_itv == 0) {
if (document.documentElement && document.documentElement.scrollTop) {
goto_top_type = 1;
} else if (document.body && document.body.scrollTop) {
goto_top_type = 2;
} else {
goto_top_type = 0;
}
if (goto_top_type > 0) {
goto_top_itv = setInterval('goto_top_timer()', 50);
}
}
}
</script>
<a href="javascript:void(0)" onclick="goto_top()">【返回頂部】</a>
相關(guān)文章
將字符串轉(zhuǎn)換成gb2312或者utf-8編碼的參數(shù)(js版)
直接在url中傳遞中文參數(shù)時,讀到的中文都是亂碼,那么我們應(yīng)該怎么將這些參數(shù)轉(zhuǎn)換呢,接下來與大家分享下將字符串轉(zhuǎn)換成utf-8或者gb2312編碼的參數(shù)的技巧2013-04-04file-loader打包圖片文件時路徑錯誤輸出為[object-module]的解決方法
這篇文章主要介紹了file-loader打包圖片文件時路徑錯誤輸出為[object-module]的解決方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-01-01IE和Firefox在JavaScript應(yīng)用中的兼容性探討
今天在使用CSS屬性的時候發(fā)現(xiàn)"cursor:hand;"在Firefox中鼠標不會變?yōu)槭中?,后來上網(wǎng)搜索了一下資料,發(fā)現(xiàn)hand這個cursor屬性在Firrefox中不兼容,使用"cursor:pointer"就都可以顯示了。2008-04-04js 在定義的時候立即執(zhí)行的函數(shù)表達式(function)寫法
如果不需要顯示調(diào)用函數(shù), 讓這個函數(shù)在定義的時候就執(zhí)行的話, 該如何寫才可以呢,接下來將詳細介紹實現(xiàn)步驟,感興趣的朋友可以了解下2013-01-01