Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Mobile Sticky Footer

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.

like image 827
JeffS Avatar asked Sep 11 '12 19:09

JeffS


People also ask

What happened to the footer widget in jQuery Mobile?

As of jQuery Mobile 1.4.0 the functionality of the footer widget has been moved to the toolbar widget.

What is the best way to make a sticky footer?

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.

What is the height of footer in jQuery?

#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.

What is the best way to add a footer to a page?

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.


1 Answers

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();
});
like image 135
Nick B Avatar answered Oct 13 '22 15:10

Nick B