0

I'm trying to replicate the fade in the background image of this site. How would I go about doing so with jQuery?

Steve Robbins
  • 13,672
  • 12
  • 76
  • 124
icantbecool
  • 482
  • 8
  • 16
  • http://api.jquery.com/fadeIn/ – Adi Jun 30 '12 at 10:17
  • 1
    possible duplicate of [JQuery - Fade In Background image](http://stackoverflow.com/questions/977090/jquery-fade-in-background-image) and just about every question in the "related" pane on the right side. – JJJ Jun 30 '12 at 10:19

2 Answers2

3

Use an image as a background image. i.e., <img /> tag. Then use jQuery's .animate() function:

$(document).ready(function(){
    $('img.bg').animate({
        opacity: 1;
    }, 1000);
});

CSS:

.bg {opacity: 0; position: absolute; top: 0; left: 0; width: 100%; height: 100%;}

HTML:

<img src="bgimage.png" class="bg" />
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
1

Working demo http://jsfiddle.net/9HTkV/ (and coz I like hulk) :P

Start with opacity 1 and then make it zero as it is fade in.

This should help :)

code

        $('.box2').animate({
            opacity: 0
        });

​

CSS in start you want Opacity to be 1 and then make it 0.

.box2 {
    height: 500px;
    width: 700px;
    background: #000000;
    opacity: 1;
}
Tats_innit
  • 33,991
  • 10
  • 71
  • 77