html jquery修改height,html - JQuery: dynamic height() with window resize() - Stack Overflow

I'm having an issue identical to this poster:

Jquery problem with height() and resize()

But the solution doesn't fix my issue. I have three stacked divs, and I want to use JQuery to make the middle one adjust in height to 100% of the window height, minus the height (23px * 2) of the other top & bottom divs. It works on resize, but it's off (short) by 16px when the document initially loads.

HTML

top

help me. seriously.

bottom

CSS

html,

body {

width:100%;

height:100%;

}

.bg {

width:315px;

height:23px;

margin:0 auto;

text-indent:-9000px;

}

#bg1 {background:url(../images/bg1.png) 0 50% no-repeat;}

#bg2 {background:url(../images/bg2.png) 0 50% no-repeat;}

#content {

width:450px;

margin:0 auto;

text-align: center;

}

JQuery

$(document).ready(function(){

resizeContent();

$(window).resize(function() {

resizeContent();

});

});

function resizeContent() {

$height = $(window).height() - 46;

$('body div#content').height($height);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值