11import dynamic from "next/dynamic" ;
2+ import { useRef } from "react" ;
3+
24const Animator = dynamic (
35 import ( "react-scroll-motion" ) . then ( ( it ) => it . Animator ) ,
46 { ssr : false }
57) ;
68
79import {
8- ScrollContainer ,
9- ScrollPage ,
10+ Animation ,
1011 batch ,
1112 Fade ,
1213 FadeIn ,
1314 Move ,
1415 MoveIn ,
1516 MoveOut ,
17+ ScrollContainer ,
18+ ScrollPage ,
1619 Sticky ,
1720 StickyIn ,
1821 ZoomIn ,
19- Animation ,
2022} from "react-scroll-motion" ;
2123
2224export default function Home ( ) {
@@ -25,71 +27,84 @@ export default function Home() {
2527 const FadeUp = batch ( Fade ( ) , Move ( ) , Sticky ( ) ) ;
2628
2729 // Make custom animation
28- const Spin = ( cycle : number ) =>
30+ const Spin = ( cycle : number , direction : "in" | "out" | "both" = "both" ) =>
2931 ( {
30- in : {
31- style : {
32- transform : ( p ) => `rotate(${ p * 360 * cycle } deg)` ,
33- } ,
34- } ,
35- out : {
36- style : {
37- transform : ( p ) => `rotate(${ p * 360 * cycle } deg)` ,
38- } ,
39- } ,
32+ in :
33+ direction === "in" || direction === "both"
34+ ? { style : { transform : ( p ) => `rotate(${ p * 360 * cycle } deg)` } }
35+ : { } ,
36+ out :
37+ direction === "out" || direction === "both"
38+ ? { style : { transform : ( p ) => `rotate(${ p * 360 * cycle } deg)` } }
39+ : { } ,
4040 } as Animation ) ;
4141
42+ const parent = useRef < HTMLDivElement > ( null ) ;
4243 return (
43- < ScrollContainer >
44- < ScrollPage >
45- < Animator animation = { batch ( Sticky ( ) , Fade ( ) , Spin ( 3 ) ) } >
46- < h1 style = { { fontSize : 50 } } > Hello!!!</ h1 >
47- </ Animator >
48- </ ScrollPage >
49- < ScrollPage >
50- < Animator animation = { batch ( Fade ( ) , Sticky ( ) , MoveOut ( 0 , - 200 ) ) } >
51- < span style = { { fontSize : 30 } } >
52- Let me show you scroll animation π
53- </ span >
54- </ Animator >
55- </ ScrollPage >
56- < ScrollPage >
57- < Animator animation = { ZoomInScrollOut } >
58- < span style = { { fontSize : 40 } } > I'm FadeUpScrollOut β¨</ span >
59- </ Animator >
60- </ ScrollPage >
61- < ScrollPage >
62- < Animator animation = { FadeUp } >
63- < span style = { { fontSize : 40 } } > I'm FadeUp β
οΈ</ span >
64- </ Animator >
65- </ ScrollPage >
66- < ScrollPage >
67- < div
68- style = { {
69- display : "flex" ,
70- justifyContent : "center" ,
71- alignItems : "center" ,
72- height : "100%" ,
73- } }
74- >
75- < span style = { { fontSize : 40 } } >
76- < Animator animation = { MoveIn ( - 1000 , 0 ) } > Hello Guys ππ»</ Animator >
77- < Animator animation = { MoveIn ( 1000 , 0 ) } > Nice to meet you ππ»ββοΈ</ Animator >
78- - I'm Dante Chun -
79- < Animator animation = { MoveOut ( 1000 , 0 ) } > Good bye βπ»</ Animator >
80- < Animator animation = { MoveOut ( - 1000 , 0 ) } > See you π</ Animator >
81- </ span >
82- </ div >
83- </ ScrollPage >
84- < ScrollPage >
85- < Animator animation = { batch ( Fade ( ) , Sticky ( ) ) } >
86- < span style = { { fontSize : 40 } } > Done</ span >
87- < br />
88- < span style = { { fontSize : 30 } } >
89- There's FadeAnimation, MoveAnimation, StickyAnimation, ZoomAnimation
90- </ span >
91- </ Animator >
92- </ ScrollPage >
93- </ ScrollContainer >
44+ < main >
45+ < section
46+ style = { { height : "100vh" , backgroundColor : "skyblue" } }
47+ > </ section >
48+
49+ < section ref = { parent } >
50+ < ScrollContainer scrollParent = { parent . current } >
51+ < ScrollPage >
52+ < Animator animation = { batch ( Sticky ( ) , Fade ( ) , Spin ( 1 , "out" ) ) } >
53+ < h1 style = { { fontSize : 50 } } > Hello!!!</ h1 >
54+ </ Animator >
55+ </ ScrollPage >
56+ < ScrollPage >
57+ < Animator animation = { batch ( Fade ( ) , Sticky ( ) , MoveOut ( 0 , - 200 ) ) } >
58+ < span style = { { fontSize : 30 } } >
59+ Let me show you scroll animation π
60+ </ span >
61+ </ Animator >
62+ </ ScrollPage >
63+ < ScrollPage >
64+ < Animator animation = { ZoomInScrollOut } >
65+ < span style = { { fontSize : 40 } } > I'm FadeUpScrollOut β¨</ span >
66+ </ Animator >
67+ </ ScrollPage >
68+ < ScrollPage >
69+ < Animator animation = { FadeUp } >
70+ < span style = { { fontSize : 40 } } > I'm FadeUp β
οΈ</ span >
71+ </ Animator >
72+ </ ScrollPage >
73+ < ScrollPage >
74+ < div
75+ style = { {
76+ display : "flex" ,
77+ justifyContent : "center" ,
78+ alignItems : "center" ,
79+ height : "100%" ,
80+ } }
81+ >
82+ < span style = { { fontSize : 40 } } >
83+ < Animator animation = { MoveIn ( - 1000 , 0 ) } > Hello Guys ππ»</ Animator >
84+ < Animator animation = { MoveIn ( 1000 , 0 ) } >
85+ Nice to meet you ππ»ββοΈ
86+ </ Animator >
87+ - I'm Dante Chun -
88+ < Animator animation = { MoveOut ( 1000 , 0 ) } > Good bye βπ»</ Animator >
89+ < Animator animation = { MoveOut ( - 1000 , 0 ) } > See you π</ Animator >
90+ </ span >
91+ </ div >
92+ </ ScrollPage >
93+ < ScrollPage >
94+ < Animator animation = { batch ( Fade ( ) , Sticky ( ) ) } >
95+ < span style = { { fontSize : 40 } } > Done</ span >
96+ < br />
97+ < span style = { { fontSize : 30 } } >
98+ There's FadeAnimation, MoveAnimation, StickyAnimation,
99+ ZoomAnimation
100+ </ span >
101+ </ Animator >
102+ </ ScrollPage >
103+ </ ScrollContainer >
104+ </ section >
105+
106+ < section style = { { height : "80vh" , backgroundColor : "blue" } } > </ section >
107+ < section style = { { height : "80vh" , backgroundColor : "green" } } > </ section >
108+ </ main >
94109 ) ;
95110}
0 commit comments