jQuery 如何使用jQuery为包装器添加高度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1078203/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 10:36:48  来源:igfitidea点击:

How to add height to wrapper with jQuery?

jquerycssheight

提问by shin

I need to add css height to each page dynamically with jQuery.

我需要使用 jQuery 为每个页面动态添加 css 高度。

So far I got the following code, but it does not add height to #wrapper.

到目前为止,我得到了以下代码,但它没有为 #wrapper 添加高度。

function getPageSizeWithScroll(){
if (window.innerHeight && window.scrollMaxY) {// Firefox
    yWithScroll = window.innerHeight + window.scrollMaxY;
    xWithScroll = window.innerWidth + window.scrollMaxX;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
    yWithScroll = document.body.scrollHeight;
    xWithScroll = document.body.scrollWidth;
} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
    yWithScroll = document.body.offsetHeight;
    xWithScroll = document.body.offsetWidth;
}
arrayPageSizeWithScroll = yWithScroll;
//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
return arrayPageSizeWithScroll;
}
var newheight = getPageSizeWithScroll() + 30;

$('#wrapper').css({'height':'newheight'});

回答by cutts

Try

尝试

$('#wrapper').css("height", newheight);

回答by buildog

or

或者

$('#wrapper').css({height:newheight+'px');

回答by Philippe Leybaert

You're setting the height to the string 'newheight', instead of the value of newheight. Simply get rid of the quotes:

您将高度设置为字符串 'newheight',而不是 newheight 的值。只需去掉引号:

$('#wrapper').css({'height':newheight});

回答by sheelpriy

you are assigning a string value to your height, all you need to remove quotes and put simply a variable containing value. like

您正在为您的高度分配一个字符串值,您只需要删除引号并简单地放置一个包含值的变量。喜欢

var newheight = getPageSizeWithScroll() + 30;

$('#wrapper').css('height':newheight);

回答by Kar

This should work:

这应该有效:

$('#wrapper').css({'height':newheight});

回答by Nooshu

Or

或者

$('#wrapper').height(newheight);

So many ways to do the same thing. height method

有很多方法可以做同样的事情。 高度法