views:

32

answers:

1

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)).css({display: 'block'}).animate({opacity: 1});
      wrapper.animate({left: -(imageSet * 104)});          

      return false; 

});
A: 

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; 

});
redsquare
yea since I didn't post that the wrapper is a ul, thus the children are li, so doing it like you suggested causes all code in the main callback to be run 5 times (1 for each time the child completes it's animation to opacity: 0, thanks for showing me bit better styling/order tho :)
Abe
@Abe - no problem, did you sort it then?
redsquare
nope its still acting weird i've uploaded it so any1 can see: http://www.southwark-woodcraft.org.uk/
Abe
@Abe - will fix it for you later this evening
redsquare
ah cheers any helps much appreciated
Abe
@redsquare did u ever get a chance to look at this? stil aint figured it myself
Abe