views:

90

answers:

1

I've got an HTML page with a few divs hidden withdisplay:none;that I'd like to be able to.fadeIn()and.fadeOut()replacing one with the other.

I've currently got a link setup that should do just that, here is the Javascript I'm trying:

$('#footer a').click(function() {                   
    $('#content > *').fadeOut('fast', function(){
        $('#contact').fadeIn('slow');
    });
    return false;
});

And here is a quick idea of the HTML layout:

<html>
<head></head>
<body>
<div id="content">
 <div id="contact"></div>
 <div id="about"></div>
 <div id="main"></div>
</div>
</body>
</html>

So, I've got the.fadeIn()as a callback to the.fadeOut(), but I still see a flash of the old content by the time the new content is fading in! Not to mention all kinds of other weirdness such as jQuery not being applied to external HTML that I insert with.load(), but that's for another post I suppose.

A: 

but I still see a flash of the old content by the time the new content is fading in!

That's most likely because of callback to fadeOut, try this instead:

$('#footer a').click(function() {                   
    $('#content > *').stop().fadeOut('fast');
    $('#contact').delay(1000).fadeIn('slow');
    return false;
});
Sarfraz
Thanks for the answer. I tried taking the .fadeIn() out of the callback, but to no avail. I figured it'd be best to have it in the callback anyway, just to ensure the content is loaded before shown.It's so simple, but doesn't work. The most frustrating of all problems!
BenjiBee
@BenjiBee: I have modified my code, try with that please.
Sarfraz
@sAc: This definitely does work, it does hide the jump, but it seems like it wouldn't be the best workaround, no? I mean, with thousands of articles on the web about shaving milliseconds of your script, it seems a bit silly to add a 1 second pause because of what seems to be a glitch!I think I may be expecting too much of built-in jQuery commands. A bit too optimistic or simplistic in my approach?
BenjiBee
@BenjiBee: Try removing the `delay` method from above code.
Sarfraz