javascript - 没有元素跳转的jQuery定位页脚

标签 javascript jquery html css

所以我使用 jQuery 将页脚绝对定位在内容不多的页面上。

我注意到的问题是页脚加载到它的正常位置,然后在 jQuery 添加类时明显跳到页面底部。无论如何要绕过这个跳跃?

        /* Position footer bottom of all pages */
    positionFooter: function () {
        var windowHeight = jQuery(window).height();
        var content = jQuery("#content").height() + jQuery("#footer-wrapper").height();
        if (windowHeight > content){
            jQuery("#content").css("padding-bottom", jQuery("#footer-wrapper").height());
            jQuery("#footer-wrapper").addClass("fixed-bottom");
        }
    }

我正在使用 window.load:

jQuery(window).load(function()

最佳答案

这个怎么样

positionFooter: function () 
        {
            var windowHeight = jQuery(window).height();
            var content = jQuery("#content").height() + jQuery("#footer-wrapper").height();
            jQuery("#footer-wrapper").addClass("fixed-bottom");
            jQuery("#footer-wrapper").hide();
            if (windowHeight > content)
            {
                jQuery("#content").css("padding-bottom", jQuery("#footer-wrapper").height());
                jQuery("#footer-wrapper").show();
            }
        }

关于javascript - 没有元素跳转的jQuery定位页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31157472/

相关文章:

javascript - IE7中的getElementsByName

javascript - 如何使用 jQuery 正确打印出 HTML 中的变量

javascript - 我将如何实现下一个/上一个按钮以循环浏览 HTML 中的表格数据

javascript - 数组中特定元素的组合

javascript - 需要在 Javascript 或 Angular 搜索时显示 JSON 中的父级和子级

javascript - 如何使用 JavaScript 显示/隐藏 HTML 元素

javascript - 通过 jquery ajax post 下载文件

javascript - 使用 chrome 时,最后一列并不总是显示在 bootstrap 折叠元素内的 html 表中

javascript - 如何在javascript中通过属性删除对象

javascript - LESS CSS 最小设置失败