Skip to content

Instantly share code, notes, and snippets.

@mattgperry
Created August 26, 2020 15:19
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattgperry/5046aedef6bdec7f28efe3712cf3b6a8 to your computer and use it in GitHub Desktop.
Save mattgperry/5046aedef6bdec7f28efe3712cf3b6a8 to your computer and use it in GitHub Desktop.
Disable pointer-events at low opacity in Framer Motion
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