I have a website that consists of multiple pages, each with varying heights.
My goal is to have the footer stay fixed at the bottom of the page if the content on the page does not fill up the browser viewport.
I attempted to achieve this using the following JavaScript:
$(function() {
if ($(document).height() > $("footer").offset().top + 44) {
$("footer").addClass('fixbottom');
}
});
$(window).resize(function() {
if ($(document).height() > $("footer").offset().top + 44) {
$("footer").addClass('fixbottom');
}
});
And the corresponding CSS:
.fixbottom {
width: 100%;
position: fixed;
bottom: 0;
}
footer {
height: 44px;
background: #7abde9;
color: #ffffff;
text-align: center;
}
The `top+44` in my jQuery code accounts for the height of my footer. I included both document ready and window resize functions to cover all scenarios, but unfortunately, it doesn't seem to work as intended.
Any assistance would be greatly appreciated.