简体   繁体   中英

jQuery Mobile Change body background image on page change

I have the following scenario, two pages with different body id. This is for setting a different background on each body. However when I navigate to page2 from page1 the background keeps being the same. Is there a way to set a background image on page change ??

PAGE1:

HTML:
<body>
   ...html content
</body>

PAGE 2:

HTML:
<body id="myOtherBg" >
   ...html content
</body>

CSS:

 body{
        background: url(../img/background_white.png) center center no-repeat;
    }

    #myOtherBg{
        background: url(../img/background_white.png) center center no-repeat;
    }

This works on a normal page load, but when reaching the page2 from page1 using jquerymobile the background doesn't change.

Any help would be appreciated, thanks in advance.

Try giving page1's body tag an id and target that in your first rule. So instead of body{...} , make it #firstBG{...} . That way page2 does not even attempt to pull the first page's background.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM