简体   繁体   中英

Align div in browser bottom

Refer the thread : Div at the browser bottom

Problem image : http://i.imgur.com/I9vVv.png http://i.stack.imgur.com/jTU5U.png

I used all the methods and it all went in wain. Is there any method in Jquery to place a div at the bottom if even the page is scrolled ?

Thanks in Advance

For browsers other than IE6, use position: fixed is enough:

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

For IE6, a general approach is to register the scroll event and dynamically change the top style property of #footer

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';
        }
    );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM