簡體   English   中英

在瀏覽器底部對齊div

[英]Align div in browser bottom

請參閱瀏覽器底部的線程: Div

問題圖像: http : //i.imgur.com/I9vVv.png http://i.stack.imgur.com/jTU5U.png

我用了所有方法,一切都白費了。 即使滾動頁面,Jquery中是否有任何方法可將div放在底部?

提前致謝

對於IE6以外的瀏覽器,使用position: fixed

#footer {
    position: fixed !important; /* IE6 hack */
    position: absolute;
    right: 0;
    bottom: 0;
    background: yellow;
}

對於IE6,一般的方法是注冊scroll事件並動態更改#footertop style屬性。

var footer = document.getElementById('footer');

// Test IE6
if (footer.currentStyle && 
    footer.currentStyle.position !== 'fixed') {
    // Set bottom to 'auto' because we would use top property
    footer.style.bottom = 'auto';
    // Only for IE6, so use window.attachEvent
    window.attachEvent(
        'onscroll',
        function() {
            var scrollTop = document.documentElement.scrollTop;
            var pageHeight = document.documentElement.offsetHeight;
            var height = footer.offsetHeight;
            footer.style.top = (scrollTop + pageHeight - height) + 'px';
        }
    );
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM