0

Well, I have an image which animates by moving to the left by 1000px. Once it stops, this image is replaced to another image. My code:

function image1() {
    $('#photo').animate({left: '1000px'}, 40000, function() {
        $('#photo').attr('src', 'image2.jpg');
       setTimeout(image1, "2000")
    });
}

The image doe move, but when it stops, it does not change.. :(

user1780468
  • 117
  • 3
  • 8

3 Answers3

2

Try this:

setTimeout(image1, 2000)

instead of this

setTimeout(image1, "2000")
AnandVeeramani
  • 1,526
  • 9
  • 15
  • it works now, my bad, the mistake was the ID was in a div which envelops the image.. so i removed the ID to put it in the image lol... thank you... IT WORKS DUDE :) – user1780468 Oct 29 '12 at 17:43
  • by the way, once the image changes, can it be animated now? i mean when the image changes to the other image, the latter animates and move to the left by 1000px. For example, I made this but does not work: function image1() { $('#photo').animate({left: '1000px'}, 40000, function() { $('#photo').attr('src', 'image2.jpg').animate({left: '1000px'}, 40000); setTimeout(image1, 2000) }); } – user1780468 Oct 29 '12 at 17:46
0

To start, the second argument to setTimeout should be a number (less than 2^31), not a string.

setTimeout(image1, 2000);
Community
  • 1
  • 1
Matt Ball
  • 354,903
  • 100
  • 647
  • 710
0

Use $(this) instead of repeating the selector.

mpaton
  • 789
  • 3
  • 14