@@ -78,11 +78,6 @@ function raf() {
7878 }
7979}
8080
81- // Will get false negative for old browsers which is okay
82- function isDocumentHidden ( ) {
83- return "hidden" in document && document . hidden ;
84- }
85-
8681// Animations created synchronously will run synchronously
8782function createFxNow ( ) {
8883 setTimeout ( function ( ) {
@@ -438,8 +433,15 @@ jQuery.speed = function( speed, easing, fn ) {
438433 easing : fn && easing || easing && ! jQuery . isFunction ( easing ) && easing
439434 } ;
440435
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+ }
443445
444446 // Normalize opt.queue - true/undefined/null -> "fx"
445447 if ( opt . queue == null || opt . queue === true ) {
@@ -464,9 +466,6 @@ jQuery.speed = function( speed, easing, fn ) {
464466
465467jQuery . fn . extend ( {
466468 fadeTo : function ( speed , to , easing , callback ) {
467- if ( isDocumentHidden ( ) ) {
468- return this ;
469- }
470469
471470 // Show any hidden elements after setting opacity to 0
472471 return this . filter ( isHidden ) . css ( "opacity" , 0 ) . show ( )
@@ -475,10 +474,6 @@ jQuery.fn.extend({
475474 . end ( ) . animate ( { opacity : to } , speed , easing , callback ) ;
476475 } ,
477476 animate : function ( prop , speed , easing , callback ) {
478- if ( isDocumentHidden ( ) ) {
479- return this ;
480- }
481-
482477 var empty = jQuery . isEmptyObject ( prop ) ,
483478 optall = jQuery . speed ( speed , easing , callback ) ,
484479 doAnimation = function ( ) {
@@ -646,17 +641,19 @@ jQuery.fx.timer = function( timer ) {
646641jQuery . fx . interval = 13 ;
647642jQuery . fx . start = function ( ) {
648643 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 ) ;
655647 }
656648} ;
657649
658650jQuery . fx . stop = function ( ) {
659- clearInterval ( timerId ) ;
651+ if ( window . cancelAnimationFrame ) {
652+ window . cancelAnimationFrame ( timerId ) ;
653+ } else {
654+ clearInterval ( timerId ) ;
655+ }
656+
660657 timerId = null ;
661658} ;
662659
0 commit comments