Jonathan Lafleur
Jonathan Lafleur

Reputation: 493

jQuery Infinite Carousel with Thumbnail

I'm making a slider and I got some problem with my thumbnail, they animate faster then the fade of the main image, (After a couple of thumb animate, they are asyncrone with the animate of the main slide... they need to be at the same moment) they have the same speed, so I don't understand why that producing this error...

jQuery(document).ready(function(){
    speed = 8000;
    max_slide = jQuery(".slides_control div.fps-slide").size();
    val_x = 0;
    run = setInterval('rotate()', speed);

    jQuery("#slider").hover(
        function () { clearInterval(run); }, 
        function () { run = setInterval('rotate()', speed); }
    );


});



function rotate() {
    thumbFirst = jQuery(".fps-pagination li:first-child");
    thumbContainer = jQuery(".fps-pagination");
    animationSpeed = 800;
    if (val_x > max_slide) { val_x = 0 }

    thumbFirst.clone().appendTo(jQuery(".fps-pagination"));

    jQuery(".slides_control div.fps-slide:eq("+val_x+")").animate({"opacity":"0"}, { queue: false, duration: animationSpeed }); 
    val_x++;
    jQuery(".slides_control div.fps-slide:eq("+val_x+")").animate({"opacity":"1"}, { queue: false, duration: animationSpeed });

    thumbContainer.animate(
        {"top":"-137px"},
        {queue:false, duration: animationSpeed, 
        complete: function() { 
            thumbFirst.remove(); 
            thumbContainer.css({"top": "0px"})
        }
    });
}

jsFiddle : http://jsfiddle.net/AY3y2/1/ (Not working well in this environement) Live code: http://webserver.lewebsimple.ca/~tempcode/

Upvotes: 0

Views: 1003

Answers (1)

sebacipo
sebacipo

Reputation: 810

can you make a short jsfiddle example???

Edit

use this rotate function, your problem was in if val_x > maxSlide it must be >= and after the val_X ++, but try it

function rotate() {
    thumbFirst = jQuery(".fps-pagination li:first-child");
    thumbContainer = jQuery(".fps-pagination");
    animationSpeed = 800;


    thumbFirst.clone().appendTo(jQuery(".fps-pagination"));

    jQuery(".slides_control div.fps-slide:eq(" + val_x + ")").animate({ "opacity": "0" }, { queue: false, duration: animationSpeed });
    val_x++;
    if (val_x >= max_slide) { val_x = 0 }
    jQuery(".slides_control div.fps-slide:eq(" + val_x + ")").animate({ "opacity": "1" }, { queue: false, duration: animationSpeed });

    console.log(jQuery(".slides_control div.fps-slide:eq(" + val_x + ")").length + "valor x " + val_x);

    thumbContainer.animate({ "top": "-137px" }, { queue: false, duration: animationSpeed, complete: function () { thumbFirst.remove(); thumbContainer.css({ "top": "0px" }) } });
}

Upvotes: 1

Related Questions