@@ -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 ( ) {
@@ -446,8 +441,15 @@ jQuery.speed = function( speed, easing, fn ) {
446441 easing : fn && easing || easing && ! jQuery . isFunction ( easing ) && easing
447442 } ;
448443
449- opt . duration = jQuery . fx . off ? 0 : typeof opt . duration === "number" ? opt . duration :
450- opt . duration in jQuery . fx . speeds ? jQuery . fx . speeds [ opt . duration ] : jQuery . fx . speeds . _default ;
444+ // Go to the end state if fx are off or if document is hidden
445+ if ( jQuery . fx . off || document . hidden ) {
446+ opt . duration = 0 ;
447+
448+ } else {
449+ opt . duration = typeof opt . duration === "number" ?
450+ opt . duration : opt . duration in jQuery . fx . speeds ?
451+ jQuery . fx . speeds [ opt . duration ] : jQuery . fx . speeds . _default ;
452+ }
451453
452454 // normalize opt.queue - true/undefined/null -> "fx"
453455 if ( opt . queue == null || opt . queue === true ) {
@@ -472,21 +474,13 @@ jQuery.speed = function( speed, easing, fn ) {
472474
473475jQuery . fn . extend ( {
474476 fadeTo : function ( speed , to , easing , callback ) {
475- if ( isDocumentHidden ( ) ) {
476- return this ;
477- }
478-
479477 // show any hidden elements after setting opacity to 0
480478 return this . filter ( isHidden ) . css ( "opacity" , 0 ) . show ( )
481479
482480 // animate to the value specified
483481 . end ( ) . animate ( { opacity : to } , speed , easing , callback ) ;
484482 } ,
485483 animate : function ( prop , speed , easing , callback ) {
486- if ( isDocumentHidden ( ) ) {
487- return this ;
488- }
489-
490484 var empty = jQuery . isEmptyObject ( prop ) ,
491485 optall = jQuery . speed ( speed , easing , callback ) ,
492486 doAnimation = function ( ) {
@@ -654,18 +648,18 @@ jQuery.fx.timer = function( timer ) {
654648jQuery . fx . interval = 13 ;
655649
656650jQuery . fx . start = function ( ) {
657- if ( ! timerId ) {
658- if ( window . requestAnimationFrame ) {
659- timerId = true ;
660- window . requestAnimationFrame ( raf ) ;
661- } else {
662- timerId = setInterval ( jQuery . fx . tick , jQuery . fx . interval ) ;
663- }
664- }
651+ timerId = window . requestAnimationFrame ?
652+ window . requestAnimationFrame ( raf ) :
653+ setInterval ( jQuery . fx . tick , jQuery . fx . interval ) ;
665654} ;
666655
667656jQuery . fx . stop = function ( ) {
668- clearInterval ( timerId ) ;
657+ if ( window . cancelAnimationFrame ) {
658+ window . cancelAnimationFrame ( timerId ) ;
659+ } else {
660+ clearInterval ( timerId ) ;
661+ }
662+
669663 timerId = null ;
670664} ;
671665
0 commit comments