@@ -78,11 +78,6 @@ function raf() {
78
78
}
79
79
}
80
80
81
- // Will get false negative for old browsers which is okay
82
- function isDocumentHidden ( ) {
83
- return "hidden" in document && document . hidden ;
84
- }
85
-
86
81
// Animations created synchronously will run synchronously
87
82
function createFxNow ( ) {
88
83
setTimeout ( function ( ) {
@@ -438,8 +433,15 @@ jQuery.speed = function( speed, easing, fn ) {
438
433
easing : fn && easing || easing && ! jQuery . isFunction ( easing ) && easing
439
434
} ;
440
435
441
- opt . duration = jQuery . fx . off ? 0 : typeof opt . duration === "number" ? opt . duration :
442
- opt . duration in jQuery . fx . speeds ? jQuery . fx . speeds [ opt . duration ] : jQuery . fx . speeds . _default ;
436
+ // Go to the end state if fx are off or if document is hidden
437
+ if ( jQuery . fx . off || document . hidden ) {
438
+ opt . duration = 0 ;
439
+
440
+ } else {
441
+ opt . duration = typeof opt . duration === "number" ?
442
+ opt . duration : opt . duration in jQuery . fx . speeds ?
443
+ jQuery . fx . speeds [ opt . duration ] : jQuery . fx . speeds . _default ;
444
+ }
443
445
444
446
// Normalize opt.queue - true/undefined/null -> "fx"
445
447
if ( opt . queue == null || opt . queue === true ) {
@@ -464,9 +466,6 @@ jQuery.speed = function( speed, easing, fn ) {
464
466
465
467
jQuery . fn . extend ( {
466
468
fadeTo : function ( speed , to , easing , callback ) {
467
- if ( isDocumentHidden ( ) ) {
468
- return this ;
469
- }
470
469
471
470
// Show any hidden elements after setting opacity to 0
472
471
return this . filter ( isHidden ) . css ( "opacity" , 0 ) . show ( )
@@ -475,10 +474,6 @@ jQuery.fn.extend({
475
474
. end ( ) . animate ( { opacity : to } , speed , easing , callback ) ;
476
475
} ,
477
476
animate : function ( prop , speed , easing , callback ) {
478
- if ( isDocumentHidden ( ) ) {
479
- return this ;
480
- }
481
-
482
477
var empty = jQuery . isEmptyObject ( prop ) ,
483
478
optall = jQuery . speed ( speed , easing , callback ) ,
484
479
doAnimation = function ( ) {
@@ -646,17 +641,19 @@ jQuery.fx.timer = function( timer ) {
646
641
jQuery . fx . interval = 13 ;
647
642
jQuery . fx . start = function ( ) {
648
643
if ( ! timerId ) {
649
- if ( window . requestAnimationFrame ) {
650
- timerId = true ;
651
- window . requestAnimationFrame ( raf ) ;
652
- } else {
653
- timerId = setInterval ( jQuery . fx . tick , jQuery . fx . interval ) ;
654
- }
644
+ timerId = window . requestAnimationFrame ?
645
+ window . requestAnimationFrame ( raf ) :
646
+ setInterval ( jQuery . fx . tick , jQuery . fx . interval ) ;
655
647
}
656
648
} ;
657
649
658
650
jQuery . fx . stop = function ( ) {
659
- clearInterval ( timerId ) ;
651
+ if ( window . cancelAnimationFrame ) {
652
+ window . cancelAnimationFrame ( timerId ) ;
653
+ } else {
654
+ clearInterval ( timerId ) ;
655
+ }
656
+
660
657
timerId = null ;
661
658
} ;
662
659
0 commit comments