I have a single page app. DIV
is absolute positioned. Content is ajax'd into this DIV
. The content varies in length from a few hundred px
height to 1500+px in height.
This container must remain absolute because I am using jQuery easing effects to preform content transitions.
Problem is that the DIV
is cut off at the bottom. I would like a buffer of 100px at the end of the content DIV
.
My idea is to use a relative DIV
behind it with a negative z-index while using the height of the content DIV
and adjusting by 100px plus to create a buffer.
Getting the height of content DIV
doesn't seem to work. So I'm getting the height of the document instead *(maybe I'm doing this wrong?)*.
The problem with getting the height of the document is that it keeps growing on each iteration which is not the true length of the content DIV
.
function adjustPageBottom() {
var h;
h = $(document).height();
$("#pad_bottom").css( 'height', h+'px' );
}
So I decided to make an array which can store the previous height values:
var heights = [];
function adjustPageBottom() {
var h, res;
h = $(document).height();
heights.push(h);
switch (heights.length) {
case 3:
heights.shift();
case 2:
res = heights[1] - heights[0];
break;
case 1:
res = heights[0];
break;
}
$("#pad_bottom").css( 'height', res+'px' );
}
This approach works but I'm not ecstatic about it. I need a simpler solution. How can I do this? Perhaps pure CSS or other simple alternatives exist? Please give recommendations. Or perhaps optimize my code? Thanks.