Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

jQuery animate callback problem

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to dynamically set the form action using jQuery.
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)

861 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