11import React , { useState , useEffect } from "react"
22import styled from "styled-components"
3- import anime from "anime "
3+ import anime from "animejs "
44
55import Landing from "../components/landing"
66import Values from "../components/values"
@@ -31,24 +31,34 @@ const IndexPage = () => {
3131 const DOM = { } ;
3232 const shapes = [
3333 {
34- path : "M1097.71 325.749C998.758 479.321 773.301 300.383 620.828 417.246C533.189 484.417 582.901 683.182 487.244 742.999C345.661 831.533 157.766 799.075 114.455 665.972C50.3149 468.857 246.827 454.214 315.253 370.857C417.892 245.821 141.549 21.1992 512.274 -0.79818C697.581 -11.7936 1191.95 179.503 1097.71 325.749Z" ,
35- pathAlt : 'M778.388 350.375C755.786 279.743 687.273 226.063 606.753 187.216C526.233 148.369 378.484 111.51 295.975 173.09C213.467 234.67 150.475 322.122 126.46 431.601C102.445 541.08 192.147 695.762 327.759 757.918C463.372 820.074 648.426 774.87 736.715 667.51C825.005 560.15 800.99 421.006 778.388 350.375Z' ,
36- scaleX : 1.2 ,
37- scaleY : 1 ,
34+ path : [ "M329.085 554.908C281.328 450.071 280.786 -9.26052 228.705 -40.6883C176.623 -72.1161 -52.9267 148.72 -1.85414 326.836C54.3956 523.008 268.363 554.736 345.912 641.025C434.268 739.339 482.986 1111.32 685.982 951.743C791.023 869.169 697.639 670.034 582.808 666.807C493.816 664.307 376.842 659.746 329.085 554.908Z" ,
35+ "M571.999 462C723.361 343.701 695 148 938 104.5C1181 61 1560 609 1325 864.5C1151.78 1052.83 131.648 979.999 69.4995 817.5C-39.5003 532.499 420.638 580.299 571.999 462Z" ] ,
36+ pathAlt : [ "M329.085 554.908C281.328 450.071 280.786 -9.26052 228.705 -40.6883C176.623 -72.1161 -52.9267 148.72 -1.85414 326.836C54.3956 523.008 268.363 554.736 345.912 641.025C434.268 739.339 482.986 1111.32 685.982 951.743C791.023 869.169 697.639 670.034 582.808 666.807C493.816 664.307 376.842 659.746 329.085 554.908Z" ,
37+ "M571.999 462C723.361 343.701 695 148 938 104.5C1181 61 1560 609 1325 864.5C1151.78 1052.83 131.648 979.999 69.4995 817.5C-39.5003 532.499 420.638 580.299 571.999 462Z" ] ,
38+ scaleX : 1.1 ,
39+ scaleY : 1.1 ,
3840 rotate : 0 ,
39- tx : - 30 ,
40- ty : - 300 ,
41- fill : {
42- color : '#282faf ' ,
41+ tx : 0 ,
42+ ty : 0 ,
43+ fill : [ {
44+ color : '#00ffff ' ,
4345 duration : 500 ,
4446 easing : 'linear'
45- } ,
47+ } , {
48+ color : '#ffff00' ,
49+ duration : 500 ,
50+ easing : 'linear'
51+ } ] ,
4652 animation : {
47- path : {
53+ path : [ {
4854 duration : 3000 ,
4955 easing : 'easeOutElastic' ,
5056 elasticity : 600
51- } ,
57+ } , {
58+ duration : 3000 ,
59+ easing : 'easeOutElastic' ,
60+ elasticity : 600
61+ } ] ,
5262 svg : {
5363 duration : 2000 ,
5464 easing : 'easeOutElastic'
@@ -183,7 +193,8 @@ const IndexPage = () => {
183193 }
184194 ] ;
185195 DOM . svg = document . querySelector ( '.morph' ) ;
186- DOM . shapeEl = DOM . svg . querySelector ( 'path' ) ;
196+ DOM . frontShapeEl = DOM . svg ?. querySelector ( '.front-path' ) ;
197+ DOM . backShapeEl = DOM . svg ?. querySelector ( '.back-path' ) ;
187198
188199 // initShapeEl
189200 useEffect ( ( ) => {
@@ -198,37 +209,67 @@ const IndexPage = () => {
198209 translateY : shapes [ 0 ] . ty + 'px' ,
199210 rotate : shapes [ 0 ] . rotate + 'deg'
200211 } ) ;
212+
201213 } , [ ] ) ;
202214 // initShapeLoop
203215 useEffect ( ( ) => {
204- anime . remove ( DOM . shapeEl ) ;
216+ anime . remove ( DOM . frontShapeEl ) ;
217+ anime . remove ( DOM . backShapeEl ) ;
205218 anime ( {
206- targets : DOM . shapeEl ,
219+ targets : DOM . frontShapeEl ,
207220 easing : 'linear' ,
208- d : [ { value : shapes [ initShapeLoopStep ] . pathAlt , duration : 3500 } , { value : shapes [ initShapeLoopStep ] . path , duration : 3500 } ] ,
221+ d : [ { value : shapes [ initShapeLoopStep ] . pathAlt [ 0 ] , duration : 3500 } , { value : shapes [ initShapeLoopStep ] . path [ 0 ] , duration : 3500 } ] ,
209222 loop : true ,
210223 fill : {
211- value : shapes [ initShapeLoopStep ] . fill . color ,
212- duration : shapes [ initShapeLoopStep ] . fill . duration ,
213- easing : shapes [ initShapeLoopStep ] . fill . easing
224+ value : shapes [ initShapeLoopStep ] . fill [ 0 ] . color ,
225+ duration : shapes [ initShapeLoopStep ] . fill [ 0 ] . duration ,
226+ easing : shapes [ initShapeLoopStep ] . fill [ 0 ] . easing
227+ } ,
228+ direction : 'alternate'
229+ } ) ;
230+ anime ( {
231+ targets : DOM . backShapeEl ,
232+ easing : 'linear' ,
233+ d : [ { value : shapes [ initShapeLoopStep ] . pathAlt [ 1 ] , duration : 3500 } , { value : shapes [ initShapeLoopStep ] . path [ 1 ] , duration : 3500 } ] ,
234+ loop : true ,
235+ fill : {
236+ value : shapes [ initShapeLoopStep ] . fill [ 1 ] . color ,
237+ duration : shapes [ initShapeLoopStep ] . fill [ 1 ] . duration ,
238+ easing : shapes [ initShapeLoopStep ] . fill [ 1 ] . easing
214239 } ,
215240 direction : 'alternate'
216241 } ) ;
217242 } , [ initShapeLoopStep ] ) ;
218243
219244 // On step change
220245 useEffect ( ( ) => {
221- anime . remove ( DOM . shapeEl ) ;
246+ anime . remove ( DOM . frontShapeEl ) ;
247+ anime . remove ( DOM . backShapeEl ) ;
248+ anime ( {
249+ targets : DOM . frontShapeEl ,
250+ duration : shapes [ step ] . animation . path [ 0 ] . duration ,
251+ easing : shapes [ step ] . animation . path [ 0 ] . easing ,
252+ elasticity : shapes [ step ] . animation . path [ 0 ] . elasticity || 0 ,
253+ d : shapes [ step ] . path [ 0 ] ,
254+ fill : {
255+ value : shapes [ step ] . fill [ 0 ] . color ,
256+ duration : shapes [ step ] . fill [ 0 ] . duration ,
257+ easing : shapes [ step ] . fill [ 0 ] . easing
258+ } ,
259+ complete : function ( ) {
260+ setShapeLoopStep ( step ) ;
261+ }
262+ } ) ;
222263 anime ( {
223- targets : DOM . shapeEl ,
224- duration : shapes [ step ] . animation . path . duration ,
225- easing : shapes [ step ] . animation . path . easing ,
226- elasticity : shapes [ step ] . animation . path . elasticity || 0 ,
227- d : shapes [ step ] . path ,
264+ targets : DOM . backShapeEl ,
265+ duration : shapes [ step ] . animation . path [ 1 ] . duration ,
266+ easing : shapes [ step ] . animation . path [ 1 ] . easing ,
267+ elasticity : shapes [ step ] . animation . path [ 1 ] . elasticity || 0 ,
268+ d : shapes [ step ] . path [ 1 ] ,
228269 fill : {
229- value : shapes [ step ] . fill . color ,
230- duration : shapes [ step ] . fill . duration ,
231- easing : shapes [ step ] . fill . easing
270+ value : shapes [ step ] . fill [ 1 ] . color ,
271+ duration : shapes [ step ] . fill [ 1 ] . duration ,
272+ easing : shapes [ step ] . fill [ 1 ] . easing
232273 } ,
233274 complete : function ( ) {
234275 setShapeLoopStep ( step ) ;
@@ -252,11 +293,13 @@ const IndexPage = () => {
252293 const getCallbacks = ( idx ) => {
253294 return {
254295 enterViewport : ( watcher ) => {
296+ console . log ( idx ) ;
255297 setStep ( idx ) ;
256298 } ,
257299 exitViewport : ( watcher ) => {
258300 const pos = ! watcher . isAboveViewport ? idx - 1 : idx + 1 ;
259301 if ( pos <= NUM_SECTIONS && step !== pos ) {
302+ console . log ( pos ) ;
260303 setStep ( pos ) ;
261304 }
262305 }
@@ -266,7 +309,7 @@ const IndexPage = () => {
266309 return (
267310 < Background >
268311 < MorphWrap className = "morph-wrap" >
269- < AnimatedSVG path = { this . shapes [ 0 ] . pathAlt } />
312+ < AnimatedSVG frontPath = { shapes [ 0 ] . pathAlt [ 0 ] } backPath = { shapes [ 0 ] . pathAlt [ 1 ] } />
270313 </ MorphWrap >
271314 < Landing callbacks = { getCallbacks ( 0 ) } />
272315 < Values callbacks = { getCallbacks ( 1 ) } />
0 commit comments