admin管理员组

文章数量:1323739

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

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

Share Improve this question edited Aug 22, 2012 at 18:34 Jasper 76k14 gold badges152 silver badges148 bronze badges asked Aug 22, 2012 at 16:24 DaveDave 4939 silver badges22 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

When the pagecreate event fires, the pseudo-page has not yet been given the .ui-page class, so selecting by that class won't help you. I suggest using this to select the current pseudo-page instead:

$(document).delegate("#pageDetail", "pagecreate", function () {
    $(this).css('background', '#ECF2FE');//`this` refers to `#pageDetail`
});

Also notice I updated the background property rather than background-color. This is because jQuery Mobile uses gradient backgrounds which are specified under the background-image property and you can't overwrite background-image with background-color.

Here is a demo: http://jsfiddle/WSzq3/ (when you click between pages the background color changes on each pagebeforeshow event)

本文标签: javascriptjQuery mobilechange uipage background color dynamicallyStack Overflow