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 badges1 Answer
Reset to default 6When 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
版权声明:本文标题:javascript - jQuery mobile - change ui-page background color dynamically - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742121592a2421730.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论