兼容IE6的返回顶部代码

JS代码如下:


< script type = "text/javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" >< /script>
< script type = "text/javascript" >
backTop = function ( btnId ){
    var btn = document . getElementById( btnId);
    var d = document . documentElement;
    window . onscroll = set;
    btn . onclick = function (){
        btn . style . display = "none";
        window . onscroll = null;
        this . timer = setInterval( function (){
            d . scrollTop -= Math . ceil( d . scrollTop * 0.1);
            if( d . scrollTop == 0) clearInterval( btn . timer , window . onscroll = set);
        }, 10);
    };
    function set (){ btn . style . display = d . scrollTop ? 'block' : "none" }
};
backTop( 'gotopbtn');
< /script>

HTML代码更是简单:

<div id="gotopbtn">返回顶部</div>

其他就是CSS来渲染了,看CSS代码:


< style type = "text/css" >
#gotopbtn { width : 20px; height : 50px; line-height : 999px; overflow : hidden; background : url(images/scrolltop.png) no-repeat 50 % 0; position : fixed; _ position : absolute; bottom : 100px; left : 50 %; margin-left : 440px; display : none; cursor : pointer }
</ style >
<! -- [ if lt IE 6 ]>
< style type = "text/css" >
html { _ text - overflow : ellipsis }
#gotopbtn { _ position : absolute; _ top : expression( eval( document . documentElement . scrollTop + 400 ))}
</ style >
<![ endif ] -- >

if lt IE 6就是原来判断IE6下的显示的,详细的判断规则可以看这里


你可能感兴趣的:(function,css,IE,null,url,div)