cycle icon indicating copy to clipboard operation
cycle copied to clipboard

onbefore / onafter oddity with $.fx.off=true

Open ccoenen opened this issue 14 years ago • 1 comments
trafficstars

Hi there,

We're currently experiencing difficulties when we're running jQuery in fx.off-mode. We're using this for some mobile devices and a few outdated (read IE6) browsers.

The following outputs are form one slideshow, where i printed the name of the handler, along with a timestamp, followed by opts.currSlide like this:

function onAfter(curr,next,opts) {
    console.log('onAfter',Date().toString(), opts.currSlide);
}

Basically what happens is the following: If we're in regular fx.off = false mode (which is the default) we can record the following succession of handlers. It seems, "onBefore4/onAfter5" are a pair for one change.

onBefore Wed Jul 27 2011 16:24:05 GMT+0200 (W. Europe Daylight Time) 4
onAfter  Wed Jul 27 2011 16:24:06 GMT+0200 (W. Europe Daylight Time) 5
onBefore Wed Jul 27 2011 16:24:10 GMT+0200 (W. Europe Daylight Time) 5
onAfter  Wed Jul 27 2011 16:24:11 GMT+0200 (W. Europe Daylight Time) 6
onBefore Wed Jul 27 2011 16:24:15 GMT+0200 (W. Europe Daylight Time) 6
onAfter  Wed Jul 27 2011 16:24:16 GMT+0200 (W. Europe Daylight Time) 7
onBefore Wed Jul 27 2011 16:24:20 GMT+0200 (W. Europe Daylight Time) 7
onAfter  Wed Jul 27 2011 16:24:21 GMT+0200 (W. Europe Daylight Time) 8
onBefore Wed Jul 27 2011 16:24:25 GMT+0200 (W. Europe Daylight Time) 8
onAfter  Wed Jul 27 2011 16:24:26 GMT+0200 (W. Europe Daylight Time) 0

When i'm setting the $.fx.off=true the onBefore and onAfter fire almost instantly (which is ok, it's what i wanted with disabled effects), but they also probably have the wrong IDs. Now the pairing is "before7 / after7".

onBefore Wed Jul 27 2011 16:29:36 GMT+0200 (W. Europe Daylight Time) 7
onAfter  Wed Jul 27 2011 16:29:36 GMT+0200 (W. Europe Daylight Time) 7
onBefore Wed Jul 27 2011 16:29:41 GMT+0200 (W. Europe Daylight Time) 8
onAfter  Wed Jul 27 2011 16:29:41 GMT+0200 (W. Europe Daylight Time) 8
onBefore Wed Jul 27 2011 16:29:46 GMT+0200 (W. Europe Daylight Time) 0
onAfter  Wed Jul 27 2011 16:29:46 GMT+0200 (W. Europe Daylight Time) 0
onBefore Wed Jul 27 2011 16:29:51 GMT+0200 (W. Europe Daylight Time) 1
onAfter  Wed Jul 27 2011 16:29:51 GMT+0200 (W. Europe Daylight Time) 1

I have worked around this in my onAfter Handlers for now, but i think this behaviour is a bug.

ccoenen avatar Jul 27 '11 14:07 ccoenen

To clarify my point i am including my "workaround": I am simply checking which child is currenlty the "next" element and then use parent/children to get all siblings. I'll then iterate over all siblings until i find the element itself, remembering the index.

    function onAfter(curr,next,opts) {
        var n = $(next),
            pc = n.parent().children(),
            realCurrentIndex,
            idx;

        pc.each(function (index, element) {
            if (element == next) {
                realCurrentIndex = index;
                return false;
            }
        });

        console.log('onAfter', $.fx.off, opts.currSlide, realCurrentIndex);
    }

This will yield lines like this, when animations are enabled (which is the normal and working case), where the next Element is the same as the currSlide-Index.

onAfter undefined 7 7
onAfter undefined 8 8
onAfter undefined 9 9
onAfter undefined 0 0

as soon as i set $.fn.fx = false these lines will change to this:

onAfter true 9 0
onAfter true 0 1
onAfter true 1 2
onAfter true 2 3
onAfter true 3 4

this illustrates how the currSlide now hosts something else, at least something i didn't expect.

ccoenen avatar Jul 27 '11 19:07 ccoenen