Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如果文档高度小于窗口高度,则强制页脚位于页面底部_Jquery_Css_Ipad_Footer - Fatal编程技术网

Jquery 如果文档高度小于窗口高度,则强制页脚位于页面底部

Jquery 如果文档高度小于窗口高度,则强制页脚位于页面底部,jquery,css,ipad,footer,Jquery,Css,Ipad,Footer,我正在用ipad的肖像模式修复我网站的显示。问题是页面长度没有ipad的纵向显示那么长。下面是我正在谈论的图片: 我创建了一个jQuery函数,我认为它可以在文档高度没有窗口高度大时检测,然后我可以将页脚的位置设置为固定。这是我的密码: if ($(document).height() < $(window).height()) { $('#footer-wrapper').attr('style', 'position: fixed!important; bottom: 0px

我正在用ipad的肖像模式修复我网站的显示。问题是页面长度没有ipad的纵向显示那么长。下面是我正在谈论的图片:

我创建了一个jQuery函数,我认为它可以在文档高度没有窗口高度大时检测,然后我可以将页脚的位置设置为固定。这是我的密码:

if ($(document).height() < $(window).height()) {
    $('#footer-wrapper').attr('style', 'position: fixed!important; bottom: 0px;');
}

我认为这是可行的,但由于某些原因,文档说它的高度大于窗口视口,因此没有执行if语句。有人知道更可靠的实现方法吗?

只需将javascript更改为:

if ($(document.body).height() < $(window).height()) {
  $('#footer-wrapper').attr('style', 'position: fixed!important; bottom: 0px;');
}
if($(document.body).height()<$(window.height()){
$(“#页脚包装器”).attr('style','position:fixed!important;bottom:0px;');
}

不幸的是,身高可以设置为100%。下面是只处理页脚的解决方案

$(window).on('load resize scroll', function() {
    var f = $('#footer-wrapper');
    f.css({position:'static'});
    if (f.offset().top + f.height() < $(window).height()) {
        f.css({position:'fixed', bottom:'0', width:'100%'});
    }
});
$(窗口).on('load resize scroll',function(){
var f=$(“#页脚包装器”);
f、 css({位置:'static'});
如果(f.偏移量().top+f.高度()<$(窗口).height()){
f、 css({位置:'fixed',底部:'0',宽度:'100%});
}
});

这就是所谓的“粘性页脚”,您可以单独使用CSS来实现。我知道它被称为粘性页脚,但我不希望它总是粘性的或固定在底部。我只希望它在整个页面没有到达页面底部时启动(如ipad图片所示)。该网站在其他方面看起来都很不错。简单的替代方法(也是我的偏好)是使主体背景与页脚颜色相同。(您只需显式设置任何其他内容区域背景,如白色内容区域)。
$(window).on('load resize scroll', function() {
    var f = $('#footer-wrapper');
    f.css({position:'static'});
    if (f.offset().top + f.height() < $(window).height()) {
        f.css({position:'fixed', bottom:'0', width:'100%'});
    }
});