2

I'm trying to change my page's background when it goes to a new page by fading the new image in slowly behind the content of the page. However, when I try to fade in the new image, literally the whole page fades in because the div containing the background also contains the content. The div that contains the background image change is "nextImage".

<body>
<div id="nextImage">
     Bunch of Content
</div>
</div>
</body>

Here is the javascript I'm trying to get working which is on a new page:

<script type="text/javascript">
    $('#nextImage').css('background-image', 'url(Tranquil.jpg)').hide();
    $('#nextImage').fadeIn(5000);
</script>

Here's the CSS:

body 
{
    background-image:url("abstract1.jpg");
    background-repeat: no-repeat;
    background-size:100%;
    background-attachment:fixed;
    font-family:font-family: Helvetica,Arial, sans-serif;
    text-align:center;
    width: 100%;
    height: 100%;
}
#nextImage
{
    background-image="";
    background-repeat: no-repeat;
    background-size:100%;
    background-attachment:fixed;
    font-family:font-family: Helvetica,Arial, sans-serif;
    text-align:center;
    width: 100%;
    height: 100%;
    z-index:1;
}

Thanks for your help ahead of time :D

Gavin Sellers
  • 654
  • 1
  • 15
  • 27

2 Answers2

1

Well you've basically answered your own question by saying the div containing the background also contains the content

Separate the background div and content div so that you can fade the background as needed without affecting the content

<body>
   <div id="nextImage">
   </div>
   <div id="content">
       Bunch of Content
   </div>
</body>

check out my example here http://jsfiddle.net/Hn9w4/

Henesnarfel
  • 2,129
  • 1
  • 16
  • 18
0

You can use two overlayed divs (http://stackoverflow.com/questions/2941189/how-to-overlay-one-div-over-another-div) and the fade the one with the background.

Joao Almeida
  • 972
  • 2
  • 6
  • 19
  • You can use two overlayed divs (http://stackoverflow.com/questions/2941189/how-to-overlay-one-div-over-another-div) and fade the one with the background. – Joao Almeida Mar 01 '12 at 00:04