Jquery animation callback issues

Posted by ChrisOPeterson on Stack Overflow See other posts from Stack Overflow or by ChrisOPeterson
Published on 2010-12-22T01:33:32Z Indexed on 2010/12/22 1:54 UTC
Read the original article Hit count: 526

Filed under:
|
|

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");    
    });

};

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery