Search

Back

Copy Link

Library

/

Free

/

76

Wobbly

76

Wobbly

Not loading? Preview

Made by

@frameroverrides

override

hover

Override

Wobbly

Copy

Override

Copied to Clipboard!

Instructions

  1. You need to apply two overrides

  2. Apply triggerHover to your container

  3. Apply withShakingSpringAnimation to your text

  4. In the code you will see “make edits here” if you want your object to rotate more/less or text to shake differently update there.

Code Preview

import React, { useState, useEffect } from "react";
import type { ComponentType } from "react";
import { motion, useSpring } from "framer-motion";
import { createStore } from "https://framer.com/m/framer/store.js@^1.0.0";

// Make edits here
const ROTATION_AMOUNTS = [0, 5, -5, 0];
const X_MOVEMENT_AMOUNTS = [3, -3, 0];
const X_MOVEMENT_DURATIONS = [250, 500]; // durations for each x movement
const SHAKE_DURATION = 500;
const SPRING_CONFIG = { stiffness: 500, damping: 10 };
const INTERVAL_TIME = 10000; // 10 seconds


const useStore = createStore({
    shake: false,
});

export const triggerHover = (Component): ComponentType => {
    return (props) => {
        const [store, setStore] = useStore();

        useEffect(() => {
            const interval = setInterval(() => {
                setStore({ shake: true });

                setTimeout(() => setStore({ shake: false }), SHAKE_DURATION);
            }, INTERVAL_TIME);

            return () => clearInterval(interval); 
        }, []);

        return (
            <Component
                {...props}
                as={motion.div}
                animate={{ rotate: store.shake ? ROTATION_AMOUNTS : 0 }}
                transition={{ duration: SHAKE_DURATION / 1000 }}
            />
        );
    };
}

export function withShakingSpringAnimation(Component): ComponentType {
    return (props) => {
        const [store] = useStore();
        const x = useSpring(0, SPRING_CONFIG);

        useEffect(() => {
            if (store.shake) {
                x.set(X_MOVEMENT_AMOUNTS[0]);
                setTimeout(() => x.set(X_MOVEMENT_AMOUNTS[1]), X_MOVEMENT_DURATIONS[0]);
                setTimeout(() => x.set(X_MOVEMENT_AMOUNTS[2]), X_MOVEMENT_DURATIONS[1]);
            }
        }, [store.shake]);

        return <Component {...props} as={motion.div} style={{ x: x }} />;
    };
}

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.