Solved

jQuery animate callback problem

Posted on 2012-12-28
3
345 Views
Last Modified: 2012-12-28
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:
http://www.dis-hfm.com/default.htm

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

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

Open in new window

0
Comment
Question by:bbdesign
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 38726976
Try:

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

Open in new window

0
 
LVL 8

Assisted Solution

by:soupBoy
soupBoy earned 250 total points
ID: 38727010
you should probably include your time for the animation and 'wrap' your call back in a function...

Here is your code, modified:
$('#slide'+nextImage).animate({
     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
0
 

Author Comment

by:bbdesign
ID: 38727057
Ah, I was missing the function. Thanks guys!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question