Created
August 26, 2020 15:19
-
-
Save mattgperry/5046aedef6bdec7f28efe3712cf3b6a8 to your computer and use it in GitHub Desktop.
Disable pointer-events at low opacity in Framer Motion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { motion, useMotionValue, useTransform } from "framer-motion" | |
export function Overlay({ isVisible }) { | |
const opacity = useMotionValue(0) | |
const pointerEvents = useTransform( | |
opacity, | |
latest => latest < 0.5 ? "none" : "auto" | |
) | |
return ( | |
<motion.div | |
animate={{ opacity: isVisible ? 1 : 0 }} | |
style={{ opacity, pointerEvents }} | |
/> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment