Framer X » Animation » Example animations » 7. Event: Tap

7. Event: Tap

Here an onTap() event and Framer’s useCycle() hook are used to cycle between two visual states.

Code Component

export function CC07EventTap() {
    const [animate, cycle] = useCycle(
        { scale: 1, rotate: 0 },
        { scale: 1.25, rotate: 90 }
    )

    return (
        <Frame
            // Visual & layout
            size={150}
            borderRadius={30}
            background="#fff"
            center
            // Animation
            animate={animate}
            onTap={() => cycle()}
        />
    )
}

Framer Motion

export function FM07EventTap() {
    const [animate, cycle] = useCycle(
        { scale: 1, rotate: 0 },
        { scale: 1.25, rotate: 90 }
    )

    return (
        <Center>
            <motion.div
                style={{
                    width: 150,
                    height: 150,
                    borderRadius: 30,
                    background: "#fff",
                }}
                animate={animate}
                onTap={() => cycle()}
            />
        </Center>
    )
}

Override

export function Event_Tap(): Override {
    const [animate, cycle] = useCycle(
        { scale: 1, rotate: 0 },
        { scale: 1.25, rotate: 90 }
    )

    return {
        animate: animate,
        onTap() {
            cycle()
        },
    }
}

Leave a Reply