i am using the code found here jQuery - dynamic div height
<script type='text/javascript'>
$(function(){
$('#center').css({'height':(($(window).height())-162)+'px'});
$(window).resize(function(){
$('#center').css({'height':(($(window).height())-162)+'px'});
});
});
</script>
now the height change works fine when you resize the window, but if your scroll down the height does not change, this means the window property does not include things beyond the size of the browser window so if you scroll down the height does not increase
so what can i add that will be the size of the whole content not the window size
ANSWER use document instead of window
<script type='text/javascript'>
$(function(){
$('#center').css({'height':(($(document).height())-162)+'px'});
$(window).resize(function(){
$('#center').css({'height':(($(document).height())-162)+'px'});
});
});
</script>
Syntax: To set a div element height to 100% of the browser window, it can simply use the following property of CSS: height:100vh; Example: HTML.
Answer: Use the JavaScript height() method You can set the height of a <div> box dynamically using the jQuery height() method.
Basically, $(window). height() give you the maximum height inside of the browser window (viewport), and $(document). height() gives you the height of the document inside of the browser.
We use css property height: calc( 100% - div_height ); Here, Calc is a function. It uses mathematical expression by this property we can set the height content div area dynamically.
You could use:
$("body").height();
Perhaps:
$(document).height()/width()
Is what you need? Since the window contains the document and the window has a fixed width and restricts what you're viewing from the document.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With