jQuery animate callback problem

I'm getting an error attempting to change a CSS value on an animate callback. Sorry, I'm a bit new at this. The animate works, but where I insert $('#slide'+prevImage).css('left', '864px') after a comma, I get an error. Is there something wrong with my syntax? Thank you!

My test page:

My Javascript:
	var prevImage=1;
	var nextImage=1;
	var maxImage=5;
	var intervalID=setInterval(slideAnimation,1000);

	function slideAnimation(){
		if (nextImage==maxImage){nextImage=1;} else {nextImage++;}
			$('#slide'+prevImage).css('left', '864px')

Open in new window

Brad BansnerWeb DeveloperAsked:
Who is Participating?
käµfm³d 👽Connect With a Mentor Commented:

$('#slide'+nextImage).animate({left:'-=864px'}, function() {
	$('#slide'+prevImage).css('left', '864px');

Open in new window

soupBoyConnect With a Mentor Commented:
you should probably include your time for the animation and 'wrap' your call back in a function...

Here is your code, modified:
     left:'-=864px'}, 500, function(){
     $('#slide'+prevImage).css('left', '864px')

Open in new window

Here is a jsFiddle showing an example I just created: Animate using Jquery will callback
Brad BansnerWeb DeveloperAuthor Commented:
Ah, I was missing the function. Thanks guys!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.