richardscarrott / jquery-ui-carousel

jQuery RS Carousel is a responsive and touch-enabled carousel written on top of jQuery and the jQuery UI Widget Factory providing a full and familiar API in less than 2.6kB minified and gzipped.
http://richardscarrott.github.io/jquery-ui-carousel/
192 stars 56 forks source link

afterAnimate and beforeAnimate are fired when page loads #33

Closed simonlagneaux closed 12 years ago

simonlagneaux commented 12 years ago

The afterAnimate and beforeAnimate functions are fired mulitple times (same as the number of slides) when page loads.

richardscarrott commented 12 years ago

Off the top of my head I can't think why it would fire the same number of times as the number of slides however I know both the beforeAnimate and afterAnimate callbacks will fire once each on init as it jumps to the first slide (or the options.startAt slide) without preventing these callbacks which probably isn't desired. mmm and they're likely called again if the continuous extension is included to take into account the cloned items... I'll take a closer look into this when I get some time.

simonlagneaux commented 12 years ago

Great, thanks !

richardscarrott commented 12 years ago

I've changed how this works in 0.8.6 - it'll now still be called on page load (because goToPage is fired on load) however rather than simply ignoring the callback when animate is set to false I'm now passing in a flag to determine whether the transition was animated or not. This should help if you're transitioning something in (a caption for example) before or after animate so you can determine whether to run the callback - does this help in your situation? (also, just to note, if you decide to upgrade to 0.8.6 there have been a number of option changes so you might need to read through the docs again).

So you might do something like this:

$('#carousel').carousel({
    after: function (e, data) {
        if (data.animate) {
            // run some code
        }
    }
});