diff --git a/src/openseadragon.js b/src/openseadragon.js index c00673c8..5531831b 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -1675,6 +1675,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ }; } else { var aAnimQueue = [], + processing = [], iRequestId = 0, iIntervalId; @@ -1685,7 +1686,15 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ if ( !iIntervalId ) { iIntervalId = setInterval( function() { if ( aAnimQueue.length ) { - aAnimQueue.shift( )[ 1 ](+new Date()); + // Process all of the currently outstanding frame + // requests, but none that get added during the + // processing. + var time = +new Date(); + processing = aAnimQueue; + aAnimQueue = []; + while ( processing.length ) { + processing.shift()[ 1 ]( time ); + } } else { // don't continue the interval, if unnecessary clearInterval( iIntervalId ); @@ -1700,12 +1709,22 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ // create a mock cancelAnimationFrame function $.cancelAnimationFrame = function( requestId ) { // find the request ID and remove it - for ( var i = 0, j = aAnimQueue.length; i < j; i += 1 ) { + var i, j; + for ( i = 0, j = aAnimQueue.length; i < j; i += 1 ) { if ( aAnimQueue[ i ][ 0 ] === requestId ) { aAnimQueue.splice( i, 1 ); return; } } + + // If it's not in the queue, it may be in the set we're currently + // processing. + for ( i = 0, j = processing.length; i < j; i += 1 ) { + if ( processing[ i ][ 0 ] === requestId ) { + processing.splice( i, 1 ); + return; + } + } }; } })( window );