jquery - 粘性页脚不粘

标签 jquery html css sticky-footer

网站链接:http://www.bigideaadv.com/xsp

我正在尝试让页脚固定下来。在 Firefox 中工作正常,在 IE 和 Safari/Chrome 中不是这样。当窗口变得太小时,页脚会从固定位置切换到应该位于页面底部的更流畅的位置。

如果您缩短窗口然后滚动到页面底部,然后展开页面直到滚动条结束,页脚位于页面底部上方约 50-100 像素。有谁知道为什么会这样?

CSS:

    html, body {
                    width: 100%;
                    height: 100%;
    }

    #wrap {
        min-height:100% !important;
    }

    #wrap:before { /* Opera and IE8 "redraw" bug fix */
        content:"";
        float:left;
        height:100%;
        margin-top:-999em;
    }

    #container {
        position: relative;
        /*margin: 72px 0 172px 0;*/
        top: 72px;
        bottom: 172px;
        width: 100%;
        height: auto;
        overflow: auto;
    }

    #top_navigation {
        position: fixed;
        min-width: 1010px;
        width: 100%;
        height: 72px;
        background: url('../images/opaque.png') repeat;
        text-transform: uppercase;
        z-index: 2000;
    }

    #bottom_navigation {
        position: fixed;
        min-width: 1550px;
        width: 100%;
        height: 172px;
        background: url('../images/opaque.png') repeat;
        text-transform: uppercase;
    }

Javascript:

    int_window_width = $(window).width();
    int_window_height = $(window).height();

    if ((int_window_width <= int_min_window_width && int_window_height >= int_min_window_height) || int_window_height <= int_min_window_height) { 
        $('html').css('overflow-y', 'scroll');
        $('#bottom_navigation').css('bottom', '');
        $('#bottom_navigation').css('margin-top', '');
        $('#bottom_navigation').css('position', 'relative');
    }

    if ((int_window_width >= int_min_window_width && int_window_height >= int_min_window_height) || int_window_height >= int_min_window_height) { 
        $('html').css('overflow-y', 'hidden');
        $('#bottom_navigation').css('position', 'absolute');
        $('#bottom_navigation').css('top', '');
        $('#bottom_navigation').css('bottom', '0');
        $('#bottom_navigation').css('margin-top', '');
    }

最佳答案

如果您希望页脚在文档滚动时不移动,只需使用 position:fixed;底部:0。 IE6 不支持 position:fixed 所以你需要应用一个 polyfill:http://www.css-101.org/fixed-positioning/05.php

关于jquery - 粘性页脚不粘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9624812/

相关文章:

javascript - 这是 JavaScript 内存泄漏吗?

html - 如何在 wordpress 中添加看起来漂浮在纹理背景上的容器?

jquery - 无法使用 Cypress 在同一选项卡中打开链接

javascript - jqueryui 自动完成保持打开状态,但在单击外部时关闭

javascript - 如何实例化 JQuery 小部件 - 使用什么文本

jquery - 在 JQuery 中使用 CSS 编写 Html

html - 子菜单在悬停时消失?粘滞/固定导航

jquery - 在 Android 应用程序中包装 HTML

html - 我如何摆脱这个黑条?

javascript - jQuery 插件给出 "jQuery is not defined"