@@ -30,16 +30,21 @@ function ThemeNav () {
3030 // Set scroll monitor
3131 self . win . on ( 'scroll' , function ( ) {
3232 if ( ! self . linkScroll ) {
33- self . winScroll = true ;
33+ if ( ! self . winScroll ) {
34+ self . winScroll = true ;
35+ requestAnimationFrame ( function ( ) { self . onScroll ( ) ; } ) ;
36+ }
3437 }
3538 } ) ;
36- setInterval ( function ( ) { if ( self . winScroll ) self . onScroll ( ) ; } , 25 ) ;
3739
3840 // Set resize monitor
3941 self . win . on ( 'resize' , function ( ) {
40- self . winResize = true ;
42+ if ( ! self . winResize ) {
43+ self . winResize = true ;
44+ requestAnimationFrame ( function ( ) { self . onResize ( ) ; } ) ;
45+ }
4146 } ) ;
42- setInterval ( function ( ) { if ( self . winResize ) self . onResize ( ) ; } , 25 ) ;
47+
4348 self . onResize ( ) ;
4449 } ) ;
4550 } ;
@@ -168,4 +173,34 @@ if (typeof(window) != 'undefined') {
168173 window . SphinxRtdTheme = { StickyNav : module . exports . ThemeNav } ;
169174}
170175
176+
177+ // requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
178+ // https://gist.github.com/paulirish/1579671
179+ // MIT license
180+
181+ ( function ( ) {
182+ var lastTime = 0 ;
183+ var vendors = [ 'ms' , 'moz' , 'webkit' , 'o' ] ;
184+ for ( var x = 0 ; x < vendors . length && ! window . requestAnimationFrame ; ++ x ) {
185+ window . requestAnimationFrame = window [ vendors [ x ] + 'RequestAnimationFrame' ] ;
186+ window . cancelAnimationFrame = window [ vendors [ x ] + 'CancelAnimationFrame' ]
187+ || window [ vendors [ x ] + 'CancelRequestAnimationFrame' ] ;
188+ }
189+
190+ if ( ! window . requestAnimationFrame )
191+ window . requestAnimationFrame = function ( callback , element ) {
192+ var currTime = new Date ( ) . getTime ( ) ;
193+ var timeToCall = Math . max ( 0 , 16 - ( currTime - lastTime ) ) ;
194+ var id = window . setTimeout ( function ( ) { callback ( currTime + timeToCall ) ; } ,
195+ timeToCall ) ;
196+ lastTime = currTime + timeToCall ;
197+ return id ;
198+ } ;
199+
200+ if ( ! window . cancelAnimationFrame )
201+ window . cancelAnimationFrame = function ( id ) {
202+ clearTimeout ( id ) ;
203+ } ;
204+ } ( ) ) ;
205+
171206} , { "jquery" :"jquery" } ] } , { } , [ "sphinx-rtd-theme" ] ) ;
0 commit comments