I have a wrapper positioned to center with an y-repeated background image:
...some content
&
this is how i answered that
<script type="text/javascript">
function resizebg(){
$('#background').css("height", $(document).height());
}
$(window).resize(function(){
resizebg();
});
$(document).scroll(function(){
resizebg();
});
//initial call
resizebg();
</script>
css:
#background{
position:absolute;
top:0;
left:0;
right:0;
}
so basically on every resizing event i will overwrite the height of the div in this case an image that i use as overlay for the background and have it with opacity not so colorful also i can tint it in my case with the background color.
but thats another story
The easiest way is to add the:
$('#ID').css("height", $(document).height());
after the correct page height is determined by the browser. If the document height is changed once more re-run the above code.
You could make it absolute
and put zeros to top
and bottom
that is:
#fullHeightDiv {
position: absolute;
top: 0;
bottom: 0;
}
why don't you use width: 100%
and height: 100%
.
hows this
<style type="text/css">
#wrapper{
width: 900px;
margin: 0 auto 0 auto;
background: url('image.JPG') 250px 0px repeat-y;
}
</style>
<script src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
function handleResize() {
var h = $(window).height();
$('#wrapper').css({'height':h+'px'});
}
$(function(){
handleResize();
$(window).resize(function(){
handleResize();
});
});
</script>
</head>
<body>
<div id="wrapper">
...some content
</div>
</body>
I figured it out myself with the help of someone's answer. But he deleted it for some reason.
Here's the solution:
Listen on (window).resize event and ONLY apply inline CSS height IF the viewport is larger than the height of #truecontent, otherwise keep intact
$(function(){
var windowH = $(window).height();
var wrapperH = $('#wrapper').height();
if(windowH > wrapperH) {
$('#wrapper').css({'height':($(window).height())+'px'});
}
$(window).resize(function(){
var windowH = $(window).height();
var wrapperH = $('#wrapper').height();
var differenceH = windowH - wrapperH;
var newH = wrapperH + differenceH;
var truecontentH = $('#truecontent').height();
if(windowH > truecontentH) {
$('#wrapper').css('height', (newH)+'px');
}
})
});