diff --git a/src/components/animated/AnimatedServiceItem.tsx b/src/components/animated/AnimatedServiceItem.tsx index 6559a78d..f279bc77 100644 --- a/src/components/animated/AnimatedServiceItem.tsx +++ b/src/components/animated/AnimatedServiceItem.tsx @@ -5,7 +5,8 @@ import {AnimatedServiceItemNoRefType} from "../BlockContentTypes"; import CustomizedThemeContext from "../customized-theme-provider/CustomizedThemeContext"; import {urlFor} from "../block-content-ui/static-pages/cmsStaticPagesClient"; import ColoredPng from "../colored-png/ColoredPng"; -import {motion, useAnimationControls} from "framer-motion" +import {motion, useAnimation, useAnimationControls} from "framer-motion" +import {useInView} from "react-intersection-observer"; interface IProps { service: AnimatedServiceItemNoRefType @@ -27,9 +28,29 @@ const AnimatedServiceItem: FunctionComponent = (props: IProps) => { await controls.start({scale: 1.1}) } + const shapeControls = useAnimation(); + const [shapeRef, shapeInView] = useInView(); + + React.useEffect(() => { + if (shapeInView) { + shapeControls.start("onScreen"); + } + else { + shapeControls.start("offScreen"); + } + }, [shapeControls, shapeInView]); + + const variants = { + onScreen: {opacity: 1, transition: {duration: 2.5}}, + offScreen: {opacity: 0, transition: {duration: 1}} + }; + return ( { await animateShrinkIcon() }} @@ -84,8 +105,8 @@ const AnimatedServiceItem: FunctionComponent = (props: IProps) => { backgroundImage: `url(${urlFor(props.service.backgroundImageSrc ?? "").url() ?? ""})`, }} justifyContent='center'> - {props.service.contentTitle} + {props.service.contentTitle} = (props) => { {props.sectionData.servicesList?.map((service: AnimatedServiceItemNoRefType, index: number) => { - return })}