8000 Allow $.css().transition(). · f2er/jquery.transit@711327d · GitHub
[go: up one dir, main page]

Skip to content

Commit 711327d

Browse files
committed
Allow $.css().transition().
1 parent 2afc6f8 commit 711327d

File tree

3 files changed

+570
-20
lines changed

3 files changed

+570
-20
lines changed

jquery.transit.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -430,32 +430,38 @@
430430
}
431431

432432
if (typeof callback === 'function') callback.apply(self);
433-
434-
// Defer execution of next call. It may trigger another CSS transition,
435-
// in which case Opera can screw up when it's executed in the same
436-
// JavaScript 'tick'.
437-
if (typeof nextCall === 'function') window.setTimeout(nextCall, 0);
433+
if (typeof nextCall === 'function') nextCall();
438434
};
439435

440-
// Use the 'transitionend' event if it's available, then fallback to timers.
441436
if ((i > 0) && (transitionEnd)) {
437+
// Use the 'transitionend' event if it's available.
442438
bound = true;
443439
self.bind(transitionEnd, cb);
444440
} else {
445-
// Durations that are too slow will get transitions mixed up. (Tested
446-
// on Mac/FF 7.0.1)
447-
if ((support.transition === 'MozTransition') && (i < 25)) i = 25;
441+
// Fallback to timers if the 'transitionend' event isn't supported.
448442
window.setTimeout(cb, i);
449443
}
450444
};
451445

446+
// Defer running. This allows the browser to paint any pending CSS it hasn't
447+
// painted yet before doing the transitions.
448+
var deferredRun = function(next) {
449+
var i = 0;
450+
451+
// Durations that are too slow will get transitions mixed up.
452+
// (Tested on Mac/FF 7.0.1)
453+
if ((support.transition === 'MozTransition') && (i < 25)) i = 25;
454+
455+
window.setTimeout(function() { run(next); }, i);
456+
};
457+
452458
// Use jQuery's fx queue.
453459
if (typeof queue === 'string')
454-
self.queue(queue, run);
460+
self.queue(queue, deferredRun);
455461
else if (queue)
456-
self.queue(run);
462+
self.queue(deferredRun);
457463
else
458-
run();
464+
deferredRun();
459465

460466
// Chainability.
461467
return this;

site/index.haml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ title: Your new Proton site
545545
.box{style: 'left: 10px; top: 10px;'}
546546

547547
-# ============================================================================
548-
%h2 Effect queue
548+
%h2 Chaining / effect queue
549549
.info
550550

551551
:markdown
@@ -575,20 +575,15 @@ title: Your new Proton site
575575
.info
576576

577577
:markdown
578-
It's a common idiom to do *.css({ .. }).animate({ .. })* in jQuery. However,
579-
this will not work in *.transition* given how CSS transitions work.
580-
You will need to chain two *.transition* calls.
578+
You can chain *css* and *transition* together (*.css({ .. }).transition({ .. })*).
581579

582580
%article
583581
.hover
584582
.code
585-
%p
586-
Do a transition with 0 duration, then call the
587-
actual transition after it.
588583
%pre
589584
!= "$('.box')."
590585
%br<>
591-
!= " transition({ x: '-800px' }, <b>0</b>)."
586+
!= " css({ x: '-800px' })."
592587
%br<>
593588
!= " transition({ x: 0 });"
594589

0 commit comments

Comments
 (0)
0