Search

Back

Copy Link

Library

/

Free

/

80

Levitate

80

Levitate

Not loading? Preview

Made by

@frameroverrides

override

none

Override

Levitate

Copy

Override

Copied to Clipboard!

Instructions

Apply to frames, not images. Wrap images in a frame then apply this effect.

Code Preview

import { motion, useAnimation } from "framer-motion"
import React, { useEffect } from "react"
import type { ComponentType } from "react"

// Control height of levitation
const maxHeight = -42 // max height
const minHeight = -15 // min height

// Animation Controls
const duration = 3.5
const times = [0, 0.5, 1]
const ease = "easeInOut"
const repeat = Infinity

// Float to a specific value
export function withSpecificValue(Component): ComponentType {
    return (props) => {
        const controls = useAnimation()

        useEffect(() => {
            controls.start({
                y: [0, maxHeight, 0],
                transition: {
                    duration: duration,
                    times: times,
                    ease: ease,
                    repeat: repeat,
                },
            })
        }, [controls])

        return <Component {...props} as={motion.div} animate={controls} />
    }
}

// Float to a random value
export function withRandomValue(Component): ComponentType {
    return (props) => {
        const controls = useAnimation()

        useEffect(() => {
            const randomHeight =
                Math.floor(Math.random() * (maxHeight - minHeight + 1)) +
                minHeight

            controls.start({
                y: [0, randomHeight, 0],
                transition: {
                    duration: duration,
                    times: times,
                    ease: ease,
                    repeat: repeat,
                },
            })
        }, [controls])

        return <Component {...props} as={motion.div} animate={controls} />
    }
}

Terms of Use for Free Assets

By accessing and using this Framer Override Library, you agree to the following terms:

All code snippets provided are available for your personal and professional use. This includes personal websites, client projects, and other website projects in Framer. You are strictly prohibited from sharing, redistributing, selling these code snippets, or creating derivative works for resale or distribution. Unauthorized sharing, distribution, or selling of these code snippets is a breach of these terms and may result in termination of your access to this library, along with potential legal action.