开发者

Jquery Animation callback affecting the wrong elements

Hey I trying to make a sort of slider but having a problem getting the loop to 'reset'. The idea is to have the elements animated to fade opacity and when finished make them hidden so that the ".is(:visible)" won't be triggered after the loop has been reset. However the callback function is affecting the elements that are having their opacity animated to '1', and at the wrong time. I'm guessing it's something simple that I don't know about animations yet as I'm a bit of a jQuery newb.

    $('a#galleryArrow').bind('click', function(){

      wrapper.children().slice(imageSet,(imageSet + 5)).animate({opacity: 0}, function() {$(this).hide();});

      if (wrapper.children(':last-child').is(':visible')) { imageSet = 0; } 
      else { imageSet = imageSet + 5; }

      wrapper.children().slice(imageSet, (imageSet + 5)开发者_如何学C).css({display: 'block'}).animate({opacity: 1});
      wrapper.animate({left: -(imageSet * 104)});          

      return false; 

});


First try moving the second animate to inside the first animate callback so they wont conflict.

$('a#galleryArrow').bind('click', function(){

      wrapper.children()
             .slice(imageSet,(imageSet + 5))
             .animate({opacity: 0}, function() {

                $(this).hide();

                if (wrapper.children(':last-child').is(':visible')) { 
                    imageSet = 0; 
                } 
                else { 
                    imageSet = imageSet + 5; 
                }

                wrapper.children()
                       .slice(imageSet, (imageSet + 5))
                       .css({display: 'block'})
                       .animate({opacity: 1});

                wrapper.animate({left: -(imageSet * 104)});    

          });

      return false; 

});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜