jquery返回頂部-ie6配合css運算式。

來源:互聯網
上載者:User

標籤:返回頂部   style   class   blog   code   java   

css:

.wraper{ width:980px; height:2048px; margin:0 auto; background:#ccc; }/*返回頭部*/#backToTop a{ display:block; cursor:pointer;width:25px; height:26px; text-indent:-9999em; position:absolute; left:0; top:0; z-index:10;}#backToTop .bt_bg{        background:url(http://i0.cy.com/xtl/main/20140227/backTop.png) no-repeat;_background: 0; _filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=‘http://i0.cy.com/xtl/main/20140227/backTop.png‘,sizingMethod=‘scale‘);         width:25px; height:26px ; position:absolute; left:0; top:0; z-index:8; }#backToTop { display:none; width:25px; height:26px ; position:fixed; right:50%; margin-right:-533px; bottom:110px; z-index:1; }/**針對ie6設定*/*html #backToTop { position:absolute; margin-top:expression(0 - parseInt(this.offsetHeight / 2) + (TBWindowMargin = document.documentElement && document.documentElement.scrollTop || document.body.scrollTop) + ‘px‘);}

 

html:

    <div class="wraper">            </div>    <script type="text/javascript" src="http://www1.changyou.com/scripts/jquery.min.js"></script>

 

javascript:

    $(‘body‘).append($(‘<div id="backToTop"><a href="javascript:void(0);">回到頂部</a><div class="bt_bg"></div></div>‘).hide(0));    $(window).scroll(function(){        $(‘#backToTop‘).show();        if ($(document).scrollTop() != 0)             $(‘#backToTop‘).show();        else             $(‘#backToTop‘).hide();    });    $(‘#backToTop a‘).click(function(){        $(‘html, body‘).animate({            scrollTop: 0        }, 800);        return false;    });

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.