基于jquery的返回頂部效果(兼容IE6)
更新時間:2011年01月17日 17:22:16 作者:
最近在寫一個首頁返回頂部的效果,因為IE6不兼容position:fixed的原因,一直找不到好的解決辦法。在Google了一下,有了點眉目,加上一點自己的開發(fā),總算誤打誤撞的把問題解決了。
最近也在學(xué)jquery,就順便記錄一下了。
HTML
<div class="scroll"></div>
<script type="text/javascript" src="../skins/css/jQuery.js" charset="UTF-8"></script>
<script type="text/javascript" src="../skins/css/top.js" charset="UTF-8"></script>
CSS
.scroll{
background:url(../image/scroll.gif) no-repeat center top transparent;
bottom:100px;
cursor:pointer;
height:67px;
width:18px;
position:fixed;
_position:absolute; /*兼容IE6*/
_top: expression(eval(document.documentElement.scrollTop)+700); /*700為圖片距離頂部的設(shè)定距離,可以修改。不加700則圖片緊貼在頂部滾動*/
}
html{_text-overflow:ellipsis;} /*解決IE6下圖片抖動*/
top.js
$(document).ready(function(){
var show_delay;
var scroll_left=parseInt((document.body.offsetWidth-960)/2)+961; //960為頁面寬度
$(".scroll").click(function (){
document.documentElement.scrollTop=0;
document.body.scrollTop=0;
});
$(window).resize(function (){
scroll_left=parseInt((document.body.offsetWidth-960)/2)+961;
$(".scroll").css("left",scroll_left);
});
reshow(scroll_left,show_delay);
});
function reshow(marign_l,show_d) {
$(".scroll").css("left",marign_l);
if((document.documentElement.scrollTop+document.body.scrollTop)!=0)
{
$(".scroll").css("display","block");
}
else
{
$(".scroll").css("display","none");}
if(show_d) window.clearTimeout(show_d);
show_d=setTimeout("reshow()",500);
}
最后不要忘記了jQuery.js文件哦!
HTML
復(fù)制代碼 代碼如下:
<div class="scroll"></div>
<script type="text/javascript" src="../skins/css/jQuery.js" charset="UTF-8"></script>
<script type="text/javascript" src="../skins/css/top.js" charset="UTF-8"></script>
CSS
復(fù)制代碼 代碼如下:
.scroll{
background:url(../image/scroll.gif) no-repeat center top transparent;
bottom:100px;
cursor:pointer;
height:67px;
width:18px;
position:fixed;
_position:absolute; /*兼容IE6*/
_top: expression(eval(document.documentElement.scrollTop)+700); /*700為圖片距離頂部的設(shè)定距離,可以修改。不加700則圖片緊貼在頂部滾動*/
}
html{_text-overflow:ellipsis;} /*解決IE6下圖片抖動*/
top.js
復(fù)制代碼 代碼如下:
$(document).ready(function(){
var show_delay;
var scroll_left=parseInt((document.body.offsetWidth-960)/2)+961; //960為頁面寬度
$(".scroll").click(function (){
document.documentElement.scrollTop=0;
document.body.scrollTop=0;
});
$(window).resize(function (){
scroll_left=parseInt((document.body.offsetWidth-960)/2)+961;
$(".scroll").css("left",scroll_left);
});
reshow(scroll_left,show_delay);
});
function reshow(marign_l,show_d) {
$(".scroll").css("left",marign_l);
if((document.documentElement.scrollTop+document.body.scrollTop)!=0)
{
$(".scroll").css("display","block");
}
else
{
$(".scroll").css("display","none");}
if(show_d) window.clearTimeout(show_d);
show_d=setTimeout("reshow()",500);
}
最后不要忘記了jQuery.js文件哦!
相關(guān)文章
13個絢麗的Jquery 界面設(shè)計網(wǎng)站推薦
今天共享一些令人振奮的UI教程,這些UI大部分是基于Jquery的插件,主要包括動態(tài)切換視圖的相冊、3D旋轉(zhuǎn)分享按鈕、Facebook admin Panel,下滑效果的導(dǎo)航Menu,滑翔購物車功能,漂亮的Form表單元素等等。2010-09-09
jquery實現(xiàn)紅色豎向多級向右展開的導(dǎo)航菜單效果
這篇文章主要介紹了jquery實現(xiàn)紅色豎向多級向右展開的導(dǎo)航菜單效果,涉及jquery鼠標(biāo)hover事件結(jié)合class樣式動態(tài)添加與刪除的技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-08-08
jQuery綁定事件監(jiān)聽bind和移除事件監(jiān)聽unbind用法實例詳解
這篇文章主要介紹了jQuery綁定事件監(jiān)聽bind和移除事件監(jiān)聽unbind用法,結(jié)合實例形式詳細分析了綁定事件監(jiān)聽bind和移除事件監(jiān)聽unbind的具體使用技巧與相關(guān)注意事項,需要的朋友可以參考下2016-01-01
jquery的flexigrid無法顯示數(shù)據(jù)提示獲取到數(shù)據(jù)
升級了IE10,發(fā)現(xiàn)flexigrid無法顯示數(shù)據(jù),提示獲取到了數(shù)據(jù),但沒任何報錯任何顯示,經(jīng)過試驗和跟蹤,修改如下,有類似問題的朋友可以參考下哈2013-07-07
jquery控制頁面的展開和隱藏實現(xiàn)方法(推薦)
下面小編就為大家?guī)硪黄猨query控制頁面的展開和隱藏實現(xiàn)方法(推薦)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-10-10

