我们可以使用jquery更改html或body的高度吗? [英] Can we change the html or body height using jquery?

查看:1596
本文介绍了我们可以使用jquery更改html或body的高度吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行这个语句: $('body')。height(100); 但是当我再次检查高度时,我发现它没有变化! / p>

有没有办法改变< body>


的高度

解决方案

文档主体是一个神奇的元素,并不像其他HTML元素那样工作。您的代码:

  $('body')。height(100); 

是正确的,它和

  $('body')。css({height:100}); 
$('body')。css({height:'100px'});
$('body')。attr({style:'height:100px'});

所有结果如下:

 < body style =height:100px;> 

但是,设置高度不会隐藏<100px高度以外的区域无形。您应该将主体内容封装在div中并设置其高度:

 < body> 
< div id =wrapperstyle =height:100px; overflow:hidden;>
<! - - 内容 - >
< / div>
< / body>

jQuery解决方案是:

<$ p $ wrapInner($('< div id =height-helper/>')。css({
height:100,
溢出:隐藏
}));


I am trying to run this statement: $('body').height(100); but when I check the height again, I find it unchanged!

Is there any way to change the height of the <body>?

解决方案

document body is a magical element and does not behave the way other HTML elements do. Your code:

$('body').height(100);

Is correct and it is same as:

$('body').css({height: 100});
$('body').css({height: '100px'});
$('body').attr({style: 'height: 100px'});

All result in this:

<body style="height: 100px;">

However, setting the height will not hide the area outside the 100px height invisible. You should wrap the body content inside a div and set its height instead:

<body>
    <div id="wrapper" style="height: 100px; overflow: hidden;">
        <!-- content -->
    </div>
</body>

jQuery solution would be:

$("body").wrapInner($('<div id="height-helper"/>').css({
    height: 100,
    overflow: "hidden"
}));

这篇关于我们可以使用jquery更改html或body的高度吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆