Jquery animation callback issues
- by ChrisOPeterson
I'm trying to build a simple carousel animation with jQuery. There are 3 viewable images at any one time with buttons to click on each side to go forward or backwards. The center image is raised up by 30px to be given prominence. When one of the buttons is pushed the center image should drop down then all three images move together left or right.
The initial up and down animation works but on a callback none of the other animations will work. If I hard code the direction into them only one of them works. Is there something wrong with my current code or approach?
ctr_right.click(function() { carouselAnimate("right") });
ctr_left.click(function() { carouselAnimate("left") });
function carouselAnimate(direction) {
var offset = img_width + img_offset;
img_focus.animate({"top": "+="+focus_offset}, "slow", function() {
img_left.animate({direction: "-="+offset}, "slow");
img_focus.animate({direction: "-="+offset}, "slow");
img_right.animate({direction: "-="+offset}, "slow");
});
};