1

I'm using a simple jQuery plugin to sticking footer to the bottom of page, It works fine except when I put a table in the page: screenshot But when I resize the page, it gets fixed and footer sticks to the bottom. What's wrongwith it? Is it a CSS related problem or jQuery problem?

You can view the page without table here and page with table here.

It's the jQuery script for sticking footer the bottom of page:

$(document).ready(function () {
    positionFooter();

    $(window)
        .scroll(positionFooter)
        .resize(positionFooter);

    function positionFooter() {
        var docHeight = $(document.body).height() - $("#sticky-footer-push").height();
        if (docHeight < $(window).height()) {
            var diff = $(window).height() - docHeight;
            if (!$("#sticky-footer-push").length > 0) {
                $("#footer").before('<div id="sticky-footer-push"></div>');
            }
            $("#sticky-footer-push").height(diff);
        }
    }
});

$(window).load(function () {
    $("#footer").stickyFooter();
});

// sticky footer plugin
(function ($) {
    var footer;

    $.fn.extend({
        stickyFooter: function (options) {
            footer = this;

            positionFooter();

            $(window)
                .scroll(positionFooter)
                .resize(positionFooter);

            function positionFooter() {
                var docHeight = $(document.body).height() - $("#sticky-footer-push").height();
                if (docHeight < $(window).height()) {
                    var diff = $(window).height() - docHeight;
                    if (!$("#sticky-footer-push").length > 0) {
                        $(footer).before('<div id="sticky-footer-push"></div>');
                    }
                    $("#sticky-footer-push").height(diff);
                }
            }
        }
    });
})(jQuery);
4

2 回答 2

2

在内容 div 正下方添加以下行:

<div class="clear"></div>  

CSS:

.clear {
    clear:both;
}  

您的代码如下所示:

<div id="content">
    //HERE is your table
    <hr />
    <p>categories:</p>
</div>
<div class="clear"></div>
于 2013-07-27T12:39:54.373 回答
0

可能是 CSS 问题而不是 jQuery 问题...尝试将此 CSS 添加到您的样式表(未经测试):

html, body
{
    min-height: 100%;
}
于 2013-07-27T13:17:44.323 回答