4

I am using jQuery to cross fade images.

This is the code I am using:

$('.' + currentimage).fadeOut('slow', function() {
    $('.' + selectedimage).fadeIn('slow');
});

This is fading the first image out 100% before the selected image begins to fade in. Is there a simple way to begin fading in the second image when the first image has faded out by say 60-70%?

EDIT: All good answers. I think there is a further problem. My images are not showing up on top of each other - and only 1 image is visible at a time.

Patrick
  • 6,495
  • 6
  • 51
  • 78

4 Answers4

3

Try

$('.' + currentimage).fadeOut('slow');
$('.' + selectedimage).delay(100).fadeIn('slow');
j08691
  • 204,283
  • 31
  • 260
  • 272
3

slow is 600ms so 420 would be 70%

$('.' + currentimage).fadeOut('slow');
$('.' + selectedimage).delay(420).fadeIn(600);
Adam Merrifield
  • 10,307
  • 4
  • 41
  • 58
1

You could cheat and apply part of the fade (using fadeTo, call your other function, and then continue.

$('.' + currentimage).fadeTo('slow', .6, function() {
    $('.' + selectedimage).fadeIn('slow');
    $(this).fadeOut('slow');
});
Igor
  • 33,276
  • 14
  • 79
  • 112
-1

That is because the function you are declaring there for fadeOut() is a callback function which is to be called only after the fadeOut() is complete. You should simply be able to execute one item right after the other to get the desired effect. This is not as exact as starting at X% on the fadeOut(), but you can probably adjust the fadeOut and fadeIn time to get the desired effect or throw in a delay() on the fadeIn.

$('.' + currentimage).fadeOut('slow');
$('.' + selectedimage).fadeIn('slow');
Mike Brant
  • 70,514
  • 10
  • 99
  • 103
  • The problem with this is the first image is fading to black, and then the other image only appears when the first image has finished fading out. – Patrick Aug 15 '12 at 15:52