I want a footer in Jquery Mobile, that is not fixed, but is always at the bottom of the page.
Like this: http://ryanfait.com/sticky-footer/ (but in JQuery Mobile), not like like the standard JQuery Mobile Fixed footers.
So the footer should appear at the end of the content, or the bottom of the screen, whichever is lower.
Any ideas on how to approach this?
Edit:
The basic problem, is that I seem unable to get the div with data-role=content
to actually take up the full height of the screen.
As of jQuery Mobile 1.4.0 the functionality of the footer widget has been moved to the toolbar widget.
jQuery Sticky Footer Chris Coyier on Dec 20, 2009 In general the CSS Sticky Footeris the best way to go, as it works perfectly smoothly and doesn’t require JavaScript. If the markup required simply isn’t possible, this jQuery JavaScript might be an option. HTML Just make sure the #footer is the last visible thing on your page.
#footer { height: 100px; } jQuery When the window loads, and when it is scrolled or resized, it is tested whether the pages content is shorter than the window’s height. If it is, that means there is white space underneath the content before the end of the window, so the footer should be repositioned to the bottom of the window.
In general the CSS Sticky Footeris the best way to go, as it works perfectly smoothly and doesn’t require JavaScript. If the markup required simply isn’t possible, this jQuery JavaScript might be an option. HTML Just make sure the #footer is the last visible thing on your page.
I solved this using mostly CSS. The advantages of this over the accepted answer is it will handle cases where the page size changes after the page is shown (such as browser resize, orientation change, or even more simple cases like collapsible/accordian sections). It also has much less Javascript code, and no layout math.
CSS:
html, body {
margin: 0;
padding: 0;
height: 100%;
}
[data-role=page] {
min-height: 100%;
position: relative;
}
[data-role=content] {
padding-bottom: 40px; /* based on how tall your footer is and how much gap you want */
}
[data-role=footer] {
position: absolute;
bottom: 0;
width: 100%;
height: 40px /* this can be configurable, or omitted, as long as the above padding-bottom is at least as much as the height of the footer is */
}
The absolute footer caused jQuery Mobile page transitions to show a flickering footer (particularly the "slide" transitions), so I added this small amount of Javascript:
$(document).live( 'pagebeforechange', function() {
// hide footer
$('[data-role=footer]').hide();
});
$(document).live( 'pagechange', function() {
// show footer
$('[data-role=footer]').show();
});
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