| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592 |
- ( function( v, undefined ) {
- 'use strict';
- // this one can be initialized late (on load) instead of on DOMContentLoaded
- window.addEventListener( 'load', function() {
- var columns = document.querySelectorAll( '[data-progressive-animation]' );
- if ( columns.length && ! document.body.classList.contains( 'fl-builder-active' ) ) {
- vamtam_greensock_wait( function() {
- v.addScrollHandler( {
- defaultOptions: {
- origin: 'center center',
- type: 'progressive',
- exit: true,
- delay: 0,
- mobile: false,
- pin: false,
- pinTrigger: 'center',
- },
- blockAnimations: false,
- canActivate: function( mobile ) {
- return mobile || ! v.MEDIA.layout[ 'layout-below-max' ];
- },
- buildTimeline: function( target, withExit ) {
- var timeline = new vamtamgs.TimelineLite( { paused: true } );
- var type = target.getAttribute( 'data-progressive-animation' );
- if ( type === 'dummy' ) {
- timeline.fromTo( target, 1, { opacity: 1 }, {opacity: 1 }, '0' );
- withExit && timeline.to( target, 1, { opacity: 1 }, '1' );
- } else if ( type === 'rotate' ) {
- timeline.fromTo( target, 1, { rotation: -180 }, { rotation: 0 }, '0' );
- withExit && timeline.to( target, 1, { rotation: 180 }, '1' );
- } else if ( type === 'fade' ) {
- timeline.fromTo( target, 1, {
- opacity: 0,
- }, {
- opacity: 1,
- }, '0' );
- withExit && timeline.to( target, 0.4, { opacity: 0 }, '1.6' );
- withExit && timeline.to( target, 1, { y: -100 }, '1.6' );
- // Move + Fade //
- } else if ( type === 'move-from-top' ) {
- timeline.fromTo( target, 1, {
- y: -160,
- opacity: 0,
- }, {
- y: 0,
- opacity: 1,
- }, '0' );
- withExit && timeline.to( target, 0.4, { opacity: 0 }, '1.6' );
- withExit && timeline.to( target, 1, { y: -100 }, '1.6' );
- } else if ( type === 'move-from-bottom' ) {
- timeline.fromTo( target, 1, {
- y: 100,
- opacity: 0,
- }, {
- y: 0,
- opacity: 1,
- }, '0' );
- withExit && timeline.to( target, 0.4, { opacity: 0 }, '1.6' );
- withExit && timeline.to( target, 1, { y: -50 }, '1.6' );
- } else if ( type === 'move-from-left' ) {
- timeline.fromTo( target, 1, {
- x: -160,
- opacity: 0,
- }, {
- x: 0,
- opacity: 1,
- }, '0' );
- withExit && timeline.to( target, 0.4, { opacity: 0 }, '1.6' );
- withExit && timeline.to( target, 1, { x: -100 }, '1.6' );
- } else if ( type === 'move-from-right' ) {
- timeline.fromTo( target, 1, {
- x: 160,
- opacity: 0,
- }, {
- x: 0,
- opacity: 1,
- }, '0' );
- withExit && timeline.to( target, 0.4, { opacity: 0 }, '1.6' );
- withExit && timeline.to( target, 1, { x: 100 }, '1.6' );
- // Scale //
- } else if ( type === 'scale-in' ) {
- timeline.fromTo( target, 1, {
- opacity: 0,
- scaleX: 0.0,
- scaleY: 0.0,
- }, {
- opacity: 1,
- scaleX: 1,
- scaleY: 1,
- }, '0' );
- withExit && timeline.to( target, 0.4, { opacity: 0 }, '1.6' );
- } else if ( type === 'scale-out' ) {
- timeline.fromTo( target, 1, {
- opacity: 0,
- scaleX: 2,
- scaleY: 2,
- }, {
- opacity: 1,
- scaleX: 1,
- scaleY: 1,
- }, '0' );
- withExit && timeline.to( target, 0.4, { opacity: 0 }, '1.6' );
- // Move + Scale //
- // Zoom In //
- } else if ( type === 'move-scale-in-from-top' ) {
- timeline.fromTo( target, 1, {
- y: -160,
- opacity: 0,
- scaleX: 0.6,
- scaleY: 0.6,
- }, {
- y: 0,
- opacity: 1,
- scaleX: 1,
- scaleY: 1,
- }, '0' );
- withExit && timeline.to( target, 0.4, { opacity: 0 }, '1.6' );
- withExit && timeline.to( target, 1, { y: -100 }, '1.6' );
- } else if ( type === 'move-scale-in-from-bottom' ) {
- timeline.fromTo( target, 1, {
- y: 160,
- opacity: 0,
- scaleX: 0.6,
- scaleY: 0.6,
- }, {
- y: 0,
- opacity: 1,
- scaleX: 1,
- scaleY: 1,
- }, '0' );
- withExit && timeline.to( target, 0.4, { opacity: 0 }, '1.6' );
- withExit && timeline.to( target, 1, { y: -100 }, '1.6' );
- } else if ( type === 'move-scale-in-from-left' ) {
- timeline.fromTo( target, 1, {
- x: -160,
- opacity: 0,
- scaleX: 0.6,
- scaleY: 0.6,
- }, {
- x: 0,
- opacity: 1,
- scaleX: 1,
- scaleY: 1,
- }, '0' );
- withExit && timeline.to( target, 0.4, { opacity: 0 }, '1.6' );
- withExit && timeline.to( target, 1, { x: -100 }, '1.6' );
- } else if ( type === 'move-scale-in-from-right' ) {
- timeline.fromTo( target, 1, {
- x: 160,
- opacity: 0,
- scaleX: 0.6,
- scaleY: 0.6,
- }, {
- x: 0,
- opacity: 1,
- scaleX: 1,
- scaleY: 1,
- }, '0' );
- withExit && timeline.to( target, 0.4, { opacity: 0 }, '1.6' );
- withExit && timeline.to( target, 1, { x: 100 }, '1.6' );
- // Zoom Out //
- } else if ( type === 'move-scale-out-from-top' ) {
- timeline.fromTo( target, 1, {
- y: -160,
- opacity: 0,
- scaleX: 1.6,
- scaleY: 1.6,
- }, {
- y: 0,
- opacity: 1,
- scaleX: 1,
- scaleY: 1,
- }, '0' );
- withExit && timeline.to( target, 0.4, { opacity: 0 }, '1.6' );
- withExit && timeline.to( target, 1, { y: -100 }, '1.6' );
- } else if ( type === 'move-scale-out-from-bottom' ) {
- timeline.fromTo( target, 1, {
- y: 160,
- opacity: 0,
- scaleX: 1.6,
- scaleY: 1.6,
- }, {
- y: 0,
- opacity: 1,
- scaleX: 1,
- scaleY: 1,
- }, '0' );
- withExit && timeline.to( target, 0.4, { opacity: 0 }, '1.6' );
- withExit && timeline.to( target, 1, { y: -100 }, '1.6' );
- } else if ( type === 'move-scale-out-from-left' ) {
- timeline.fromTo( target, 1, {
- x: -160,
- opacity: 0,
- scaleX: 1.6,
- scaleY: 1.6,
- }, {
- x: 0,
- opacity: 1,
- scaleX: 1,
- scaleY: 1,
- }, '0' );
- withExit && timeline.to( target, 0.4, { opacity: 0 }, '1.6' );
- withExit && timeline.to( target, 1, { x: -100 }, '1.6' );
- } else if ( type === 'move-scale-out-from-right' ) {
- timeline.fromTo( target, 1, {
- x: 160,
- opacity: 0,
- scaleX: 1.6,
- scaleY: 1.6,
- }, {
- x: 0,
- opacity: 1,
- scaleX: 1,
- scaleY: 1,
- }, '0' );
- withExit && timeline.to( target, 0.4, { opacity: 0 }, '1.6' );
- withExit && timeline.to( target, 1, { x: 100 }, '1.6' );
- // Rotate //
- } else if ( type === 'rotate-from-top-right' ) {
- timeline.fromTo( target, 1, {
- y: -200,
- x: 120,
- rotation: -10,
- opacity: 0,
- }, {
- y: 0,
- x: 0,
- rotation: 0,
- opacity: 1,
- }, '0' );
- withExit && timeline.fromTo( target, 1, { immediateRender: false, y: 0 }, { y: -70 }, '1.6' );
- } else if ( type === 'page-title' ) {
- var line = target.querySelector( '.page-header-line' );
- var desc = target.querySelector( '.desc' );
- var shadow = document.getElementById( 'sub-header' ).querySelector( '.text-shadow' );
- timeline.fromTo( target.querySelector( 'h1' ), 0.9, { y: 0, opacity: 1 }, { y: -10, opacity: 0, ease: vamtamgs.Quad.easeIn }, '0.1' );
- desc && timeline.fromTo( desc, 1, { y: 0, opacity: 1 }, { y: 30, opacity: 0, ease: vamtamgs.Quad.easeIn }, '0' );
- shadow && timeline.fromTo( shadow, 1, { opacity: 0.3 }, { opacity: 0.7, ease: vamtamgs.Quad.easeIn }, '0' );
- line && timeline.to( line, 1, { scaleX: 0, y: 30, opacity: 0, ease: vamtamgs.Quad.easeIn }, '0' );
- } else if ( type === 'custom' ) {
- timeline.to( target, 1, { className: target.getAttribute( 'data-progressive-animation-custom' ) }, '1' );
- }
- return timeline;
- },
- getPinTrigger: function( column ) {
- if ( column.options.pinTrigger === 'center' ) {
- return this.winHeight / 2 - column.height / 2;
- }
- if ( column.options.pinTrigger === 'bottom' ) {
- return this.winHeight - column.height;
- }
- if ( column.options.pinTrigger === 'top' ) {
- return 0;
- }
- },
- calculatePinDuration: function( column ) {
- if ( v.MEDIA.layout[ 'layout-below-max' ] ) {
- column.vamtamProgressiveTimeline.pinDuration = 0;
- } else if ( column.vamtamProgressiveTimeline.options.pin === 'parent' ) {
- var closestRow = column.closest( '.fl-row-content' );
- column.vamtamProgressiveTimeline.pinDuration = closestRow.offsetHeight - ( column.vamtamProgressiveTimeline.top - v.offset( closestRow ).top );
- } else {
- column.vamtamProgressiveTimeline.pinDuration = + column.vamtamProgressiveTimeline.options.pin;
- }
- },
- onresize: function() {
- var self = this;
- this.winHeight = window.innerHeight;
- this.blockAnimations = true;
- requestAnimationFrame( function() {
- // if the timeline was previously initialized - reset the progress to 0
- for ( var i = 0; i < columns.length; i++ ) {
- if ( columns[i].vamtamProgressiveTimeline.timeline ) {
- columns[i].vamtamProgressiveTimeline.timeline.progress( 0 );
- }
- if ( columns[i].vamtamProgressiveTimeline.wrapper ) {
- Object.assign( columns[i].vamtamProgressiveTimeline.pusher.style, {
- top: '',
- width: '',
- height: '',
- } );
- Object.assign( columns[i].vamtamProgressiveTimeline.wrapper.style, {
- top: '',
- width: '',
- height: '',
- position: '',
- } );
- }
- }
- requestAnimationFrame( function() {
- var cpos = window.pageYOffset;
- var i;
- var chromeWrapperFix = [];
- // measure
- for ( i = 0; i < columns.length; i++ ) {
- var columnTop = v.offset( columns[i] ).top;
- Object.assign( columns[i].vamtamProgressiveTimeline, {
- top: columnTop,
- height: columns[i].offsetHeight,
- width: columns[i].offsetWidth,
- } );
- self.calculatePinDuration( columns[i] );
- }
- // mutate
- for ( i = 0; i < columns.length; i++ ) {
- var data = columns[i].vamtamProgressiveTimeline;
- if ( self.canActivate( data.options.mobile ) ) {
- data.timeline = self.buildTimeline(
- columns[i],
- data.options.type === 'progressive' && data.options.exit
- );
- if ( data.pusher ) {
- data.pusher.parentElement.minHeight = data.options.pin + 'px';
- data.pusher.style.height = data.pinDuration + 'px';
- if ( ! data.pusher.classList.contains( 'fl-col' ) ) {
- data.pusher.style.width = data.width + 'px';
- }
- data.wrapper.style.height = data.height + 'px';
- data.wrapper.style.top = self.getPinTrigger( data ) + 'px';
- data.wrapper.classList.add( 'vamtam-pin-active' );
- }
- } else if ( data.timeline ) {
- data.timeline.seek( 1 );
- data.timeline = null;
- if ( data.pusher ) {
- data.pusher.parentElement.minHeight = '';
- data.wrapper.classList.remove( 'vamtam-pin-active' );
- /*
- Fix a weird Chrome bug where the wrapper
- behaves as if it has visibility: hidden
- after disabling the pin for narrow screens
- */
- data.wrapper.style.display = 'block';
- chromeWrapperFix.push( data.wrapper );
- /* End Chrome fix */
- }
- }
- }
- (function( wrappers ) {
- requestAnimationFrame( function() {
- wrappers.forEach( function( wrapper ) {
- wrapper.style.display = '';
- } );
- } );
- })( chromeWrapperFix );
- self.blockAnimations = false;
- self.measure( cpos );
- self.mutate( cpos );
- } );
- } );
- },
- init: function() {
- this.winHeight = window.innerHeight;
- var i, closestRow;
- // measure
- for ( i = 0; i < columns.length; i++ ) {
- var options = Object.assign( {}, this.defaultOptions, JSON.parse( columns[i].getAttribute( 'data-vamtam-animation-options' ) ) || {} );
- var columnTop = v.offset( columns[i] ).top;
- columns[i].vamtamProgressiveTimeline = {
- top: columnTop,
- height: columns[i].offsetHeight,
- width: columns[i].offsetWidth,
- options: options
- };
- this.calculatePinDuration( columns[i] );
- columns[i].style.transformOrigin = columns[i].vamtamProgressiveTimeline.options.origin;
- if ( this.canActivate( options.mobile ) ) {
- columns[i].vamtamProgressiveTimeline.timeline = this.buildTimeline(
- columns[i],
- options.type === 'progressive' && options.exit
- );
- } else {
- columns[i].vamtamProgressiveTimeline.timeline = null;
- }
- }
- // mutate
- for ( i = 0; i < columns.length; i++ ) {
- var data = columns[i].vamtamProgressiveTimeline;
- closestRow = columns[i].closest( '.fl-row' );
- closestRow && closestRow.classList.add( 'vamtam-animation-inside' );
- if ( data.options.pin !== false ) {
- closestRow.classList.add( 'vamtam-pin-inside' );
- data.pusher = document.createElement( 'div' );
- data.pusher.classList.add( 'vamtam-pin-pusher' );
- // by default Beaver Builder sets the width of the .fl-col element
- // we need to move the .fl-col class to the wrapper
- // and set the width of the original column to 100%
- if ( columns[i].classList.contains( 'fl-col' ) ) {
- data.pusher.classList.add( 'fl-col' );
- data.pusher.classList.add( 'fl-node-' + columns[i].attributes['data-node'].value );
- data.pusher.style.width = '';
- }
- data.wrapper = document.createElement( 'div' );
- data.wrapper.classList.add( 'vamtam-pin-wrapper' );
- data.wrapper.style.willChange = 'transform, position';
- data.wrapper.style.height = data.height + 'px';
- data.wrapper.style.top = this.getPinTrigger( data ) + 'px';
- columns[i].before( data.pusher );
- data.wrapper.appendChild( columns[i] );
- data.pusher.appendChild( data.wrapper );
- columns[i].style.width = '100%';
- data.pusher.parentElement.style.position = 'relative';
- if ( data.timeline && data.options.pin !== 'parent' ) {
- data.pusher.parentElement.style.minHeight = data.options.pin + 'px';
- }
- if ( this.canActivate( data.options.mobile ) ) {
- Object.assign( data.pusher.style, {
- width: data.width + 'px',
- height: data.pinDuration + 'px',
- });
- data.wrapper.classList.add( 'vamtam-pin-active' );
- }
- }
- }
- window.addEventListener( 'resize', window.VAMTAM.debounce( this.onresize, 100 ).bind( this ), false );
- },
- measure: function() {
- },
- mutate: function( cpos ) {
- if ( this.blockAnimations ) {
- return;
- }
- for ( var i = 0; i < columns.length; i++ ) {
- var data = columns[i].vamtamProgressiveTimeline;
- if ( data.timeline && cpos + this.winHeight > data.top ) {
- // natural column vertical middle
- var from = data.top + data.height / 2;
- var progress;
- if ( data.options.pin !== false ) {
- var pinTrigger;
- if ( data.options.pinTrigger === 'center' ) {
- pinTrigger = cpos + this.winHeight / 2;
- } else if ( data.options.pinTrigger === 'bottom' ) {
- pinTrigger = cpos + this.winHeight - data.height / 2;
- } else if ( data.options.pinTrigger === 'top' ) {
- pinTrigger = cpos + data.height / 2;
- }
- // pin length starts when the "natural column vertical middle"
- // aligns with the trigger (middle of the viewport, top/bottom of viewport - half column height)
- //
- // it ends after data.pinDuration - data.height px
- var pinTo = from + data.pinDuration - data.height;
- progress = 2 * ( pinTrigger - from ) / ( pinTo - from ) - 1;
- } else {
- progress = 1 - ( ( from - cpos ) / Math.min( this.winHeight / 2, from ) );
- }
- progress -= data.options.delay;
- if ( data.options.type === 'progressive' ) {
- if ( data.timeline.totalDuration() > 1 || ! columns[i].vamtamProgressiveTimeline.options.exit ) {
- // two part (entry/exit) animation
- // note that the exit is optional
- progress = Math.min( 1, Math.max( -1, progress ) ); // clip
- // progress + 1 is used so that we can avoid negative position params
- //
- // [0; 1] -> entrance animation
- // [1; 2] -> exit animation
- //
- // it's then divided by two, since the progress() method takes a [0; 1] fraction as its argument
- progress = progress + 1;
- } else {
- // only exit animation
- progress = Math.min( 1, Math.max( 0, progress ) ); // clip
- }
- data.timeline.seek( progress );
- } else {
- if ( ! data.used && progress >= 0 ) {
- data.used = true;
- data.timeline.timeScale( 2 ).play();
- } else if ( data.used ) {
- // if the animation was played once - make sure that the timeline is at its end
- data.timeline.seek( 1 );
- }
- }
- }
- }
- }
- } );
- } );
- }
- }, { passive: true });
- } )( window.VAMTAM );
|