Solved

jQuery animate callback problem

Posted on 2012-12-28
3
348 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tools for analysis of code 4 44
Clear input text 15 26
Any Way to rotate banner ads from Commission Junction? 2 36
Table header must be on top 2 20
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

679 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