How to use the framer-motion.useTransform function in framer-motion

To help you get started, we’ve selected a few framer-motion examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lintonye / useParallax / src / useParallax.ts View on Github external
export function useParallax(positiveOffset: MotionValue, ...rangeFunPairs) {
  const processedRangeFunPairs = preprocessRangeFun(rangeFunPairs)
  const getRange = index =>
    processedRangeFunPairs[index] && processedRangeFunPairs[index][0]
  const getFun = index =>
    processedRangeFunPairs[index] && processedRangeFunPairs[index][1]

  return useTransform(positiveOffset, v => {
    let lastV = 0
    for (let i = 0; i < processedRangeFunPairs.length; i++) {
      const range = getRange(i)
      const fun = getFun(i)
      if (v < range[0]) {
        const prevFun = getFun(i - 1)
        const prevRange = getRange(i - 1)
        prevFun && (lastV = prevFun(prevRange[1]))
      } else if (v <= range[1]) {
        const nv = fun(v - range[0]) + lastV
        return nv
      } else {
        /* v > range[1] */
        lastV = fun(range[1] - range[0]) + lastV
      }
    }
github madebymany / front-end-london / src / components / NavModal / index.js View on Github external
const MobileModal = ({ tickets, open, setOpen }) => {
  const [size, setSize] = useState("100%")
  const pathPos = useSpring(0, { springConfig })
  const path = useTransform(pathPos, value =>
    interpolator(transform(value, [0, 1], [0, 1]))
  )
  useEffect(() => {
    const timer = setTimeout(
      () => {
        pathPos.set(open ? 1 : 0)
      },
      open ? 400 : 500
    )

    return () => clearTimeout(timer)
  }, [open, pathPos])

  useEffect(() => {
    const getSize = debounce(() => {
      setSize(window.innerHeight)
github steveruizok / framer-controller / examples / FramerControllerNew.framerfx / code / Scroll_example.tsx View on Github external
export const RegularFrame: Override = () => {
    return { height: useTransform(controller.progress.y, v => v * 100) }
}
github lintonye / useParallax / src / useParallax.ts View on Github external
export function usePositiveOffset(
  offset: MotionValue
): MotionValue {
  return useTransform(offset, v => -v)
}