1- /* anim8js-scrollmagic 1.0.2 - anim8 ScrollMagic by Philip Diffenderfer */
1+ /* anim8js-scrollmagic 1.0.3 - anim8 ScrollMagic by Philip Diffenderfer */
22// UMD (Universal Module Definition)
33( function ( root , factory )
44{
@@ -116,7 +116,7 @@ Scene.getInvokeCallback = function(callback)
116116// .transition('*', 'AFTER') "enter"
117117// .transition(null, 'DURING') "start on during"
118118// .transition('AFTER', 'DURING') "enter from after"
119- Scene . transition = function ( expectedPrevious , expectedCurrent , getCalls )
119+ Scene . transition = function ( expectedPrevious , expectedCurrent , getCalls , onStateChange )
120120{
121121 var builder = new CallEventBuilder ( getCalls ) ;
122122 var previous = Events . INITIAL ;
@@ -126,6 +126,11 @@ Scene.transition = function(expectedPrevious, expectedCurrent, getCalls)
126126 {
127127 if ( previous !== current )
128128 {
129+ if ( onStateChange )
130+ {
131+ onStateChange . call ( this , current , previous , progress , builder ) ;
132+ }
133+
129134 if ( this . isEventMatch ( previous , expectedPrevious ) &&
130135 this . isEventMatch ( current , expectedCurrent ) )
131136 {
@@ -192,6 +197,33 @@ Scene.startDuring = function(getCalls)
192197 return this . transition ( Events . INITIAL , Events . DURING , getCalls ) ;
193198} ;
194199
200+ // Special Enter / Exit Events
201+ Scene . intro = function ( getCalls )
202+ {
203+ var onStateChange = function ( current , previous , progress , builder )
204+ {
205+ if ( ( previous === Events . INITIAL && current === this . getBefore ( ) ) || current === Events . DURING )
206+ {
207+ builder . executeInitials ( current , progress ) ;
208+ }
209+ } ;
210+
211+ return this . transition ( Events . ANY , Events . DURING , getCalls , onStateChange ) ;
212+ } ;
213+
214+ Scene . outro = function ( getCalls )
215+ {
216+ var onStateChange = function ( current , previous , progress , builder )
217+ {
218+ if ( previous === Events . INITIAL && current === this . getAfter ( ) )
219+ {
220+ builder . executeFinals ( current , progress ) ;
221+ }
222+ } ;
223+
224+ return this . transition ( Events . DURING , Events . ANY , getCalls , onStateChange ) ;
225+ } ;
226+
195227// Special During Event
196228Scene . during = function ( getCalls )
197229{
@@ -311,16 +343,28 @@ Class.define( CallBuilder,
311343 init : function ( getCalls )
312344 {
313345 this . calls = [ ] ;
346+ this . initials = [ ] ;
347+ this . finals = [ ] ;
314348
315349 getCalls . call ( this , this ) ;
316350 } ,
317351 execute : function ( )
318352 {
319- var calls = this . calls ;
320-
321- for ( var i = 0 ; i < calls . length ; i ++ )
353+ this . executeList ( this . calls , arguments ) ;
354+ } ,
355+ executeInitials : function ( )
356+ {
357+ this . executeList ( this . initials , arguments ) ;
358+ } ,
359+ executeFinals : function ( )
360+ {
361+ this . executeList ( this . finals , arguments ) ;
362+ } ,
363+ executeList : function ( list , args )
364+ {
365+ for ( var i = 0 ; i < list . length ; i ++ )
322366 {
323- calls [ i ] . apply ( this , arguments ) ;
367+ list [ i ] . apply ( this , args ) ;
324368 }
325369 } ,
326370 call : function ( callback )
@@ -329,14 +373,42 @@ Class.define( CallBuilder,
329373
330374 return this ;
331375 } ,
332- callWith : function ( context , getCalls )
376+ initial : function ( callback )
377+ {
378+ this . initials . push ( callback ) ;
379+
380+ return this ;
381+ } ,
382+ final : function ( callback )
383+ {
384+ this . finals . push ( callback ) ;
385+
386+ return this ;
387+ } ,
388+ callWith : function ( context , getCalls , getInitial , getFinal )
333389 {
334390 if ( context )
335391 {
336392 this . call ( function ( )
337393 {
338394 getCalls . apply ( context , arguments ) ;
339395 } ) ;
396+
397+ if ( getInitial )
398+ {
399+ this . initial ( function ( )
400+ {
401+ getInitial . apply ( context , arguments ) ;
402+ } ) ;
403+ }
404+
405+ if ( getFinal )
406+ {
407+ this . final ( function ( )
408+ {
409+ getFinal . apply ( context , arguments ) ;
410+ } ) ;
411+ }
340412 }
341413
342414 return this ;
@@ -353,15 +425,15 @@ Class.extend( CallEventBuilder, CallBuilder,
353425{
354426 animator : function ( query , getCalls )
355427 {
356- return this . callWith ( ScrollMagic . getAnimator ( query ) , getCalls ) ;
428+ return this . callWith ( ScrollMagic . getAnimator ( query ) , getCalls , createAnimatorInitial ( getCalls ) , createAnimatorFinal ( getCalls ) ) ;
357429 } ,
358430 animators : function ( query , getCalls )
359431 {
360- return this . callWith ( ScrollMagic . getAnimators ( query ) , getCalls ) ;
432+ return this . callWith ( ScrollMagic . getAnimators ( query ) , getCalls , createAnimatorInitial ( getCalls ) , createAnimatorFinal ( getCalls ) ) ;
361433 } ,
362434 player : function ( player , getCalls )
363435 {
364- return this . callWith ( player , getCalls ) ;
436+ return this . callWith ( player , getCalls , createMovieInitial ( getCalls ) , createMovieFinal ( ) ) ;
365437 } ,
366438 movie : function ( movie , getCalls )
367439 {
@@ -370,6 +442,45 @@ Class.extend( CallEventBuilder, CallBuilder,
370442} ) ;
371443
372444
445+ function createAnimatorInitial ( getCalls )
446+ {
447+ return function ( )
448+ {
449+ this . stop ( ) . restore ( ) ;
450+ getCalls . apply ( this , arguments ) ;
451+ this . preupdate ( 0 ) . update ( 0 ) . apply ( ) . stop ( ) ;
452+ } ;
453+ }
454+
455+ function createAnimatorFinal ( getCalls )
456+ {
457+ return function ( )
458+ {
459+ this . stop ( ) . restore ( ) ;
460+ getCalls . apply ( this , arguments ) ;
461+ this . preupdate ( 0 ) . update ( 0 ) . end ( ) . apply ( ) ;
462+ } ;
463+ }
464+
465+ function createMovieInitial ( getCalls )
466+ {
467+ return function ( )
468+ {
469+ getCalls . apply ( this , arguments ) ;
470+
471+ this . pause ( ) . apply ( this . time , true ) ;
472+ } ;
473+ }
474+
475+ function createMovieFinal ( )
476+ {
477+ return function ( )
478+ {
479+ this . end ( true , true ) ;
480+ } ;
481+ }
482+
483+
373484function CallDuringBuilder ( getCalls )
374485{
375486 this . init ( getCalls ) ;
@@ -409,6 +520,15 @@ Class.extend( CallDuringBuilder, CallBuilder,
409520 var attrimator = attrimators [ i ] ;
410521 var prop = properties [ i ] ;
411522 var value = attrimator . valueAtSearch ( now , animator . frame [ prop ] ) ;
523+ if ( value === false ) {
524+ var last = attrimator ;
525+ var lastTime = now ;
526+ while ( last . next ) {
527+ lastTime -= last . totalTime ( ) ;
528+ last = last . next ;
529+ }
530+ value = last . valueAt ( lastTime , animator . frame [ prop ] ) ;
531+ }
412532 if ( value !== false ) {
413533 animator . updated [ prop ] = true ;
414534 animator . frame [ prop ] = value ;
0 commit comments