rstacruz / jquery.transit

Super-smooth CSS3 transformations and transitions for jQuery
http://ricostacruz.com/jquery.transit
7.29k stars 864 forks source link

transitionend fallback fires too early #100

Open 3urdoch opened 11 years ago

3urdoch commented 11 years ago

The fallback for browsers that don't support the transitionend event can fire a little to early intermittently.

The culprit being the following bit of code

      } else {
        // Fallback to timers if the 'transitionend' event isn't supported.
        window.setTimeout(cb, i);
      }

This results in any code inside the callback which attempts to get the computed style returning values for the state they were in briefly before the transition completed. For example if you tired to do the following in the callback.

 var left = $(this).offset().left;

The left hand position may be slightly off where the element ended up because if the callback was fired before the animation ended completely, as I said this is intermittent, in one example it was happening to me about 30% of the time. A hack to get this to work more reliably is to simply delay calling the callback by a few milliseconds such as:

      } else {
        // Fallback to timers if the 'transitionend' event isn't supported.
        window.setTimeout(cb, i+100);
      }

But this is probably no guarantee, perhaps the animated css properties should be verified that they have reached their target value and the callback only fired once that has happened.