I have a multi-page template setup. My home screen background color is different from the other pages, but I’m finding that some of the content I’m adding into the pages isn’t long enough to reach the footer and I’m seeing the default background color set for the home screen between the background and the footer.
Is there a way to change the ui-page background color for a page before switching to it, so it fills up the gap properly?
I’d considered doing it by delegate for the page:
$(document).delegate("#pageDetail", "pagecreate", function () {
$('.ui-page').css('background-color', '#ECF2FE');
});
but that breaks when you hit the back button as it leaves the change in place.
Is there an event I can use to make this change that will fire so I can set the correct background color for each page – or is there a simpler method I’m missing?
Thanks
When the
pagecreateevent fires, the pseudo-page has not yet been given the.ui-pageclass, so selecting by that class won’t help you. I suggest usingthisto select the current pseudo-page instead:Also notice I updated the
backgroundproperty rather thanbackground-color. This is because jQuery Mobile uses gradient backgrounds which are specified under thebackground-imageproperty and you can’t overwritebackground-imagewithbackground-color.Here is a demo: http://jsfiddle.net/WSzq3/ (when you click between pages the background color changes on each
pagebeforeshowevent)