Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="root"></div>
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css2?family=Montserrat:wght@900&display=swap");
html,
body {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
    Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
}
/* Centered Large Text */
body::before {
  content: "Jello Boi"
  text-align: center;
  width: 100%;
  line-height: 100vh;
  color: lightblue;
  position: absolute;
  font-size: 120px;
  font-weight: 900;
  font-family: "Montserrat", sans-serif;
}
/* Main Background Div */
.container-div {
  width: 100%;
}
/* Jelly Blob Div */
.jelly-blob {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 300px;
  height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  mix-blend-mode: difference;
  background-color: lightgreen;
  border-radius: 150px;
  transform-origin: 50% 50%;
  transform: translate(-50%, -50%);
  will-change: width, height, transform, border;
  z-index: 999;
  pointer-events: none;
}
/* Text Inside Jelly Blob */
.inside-text {
  width: 100%;
  opacity: 1;
  color: white;
  font-size: 18px;
  text-align: center;
  font-weight: 600;
}

              
            
!

JS

              
                /*! Cursor Jelly Blob
!   By Abhay Rohit using gsap
!   Shoutout to OSUblake https://greensock.com/profile/21420-osublake/
!   for Help with the Animation Performance
!   and Cuberto https://cuberto.com/ for Animation Concept 
!*/

// Gsap Imports
import { gsap, Expo } from "https://cdn.skypack.dev/gsap@3.7.1";

// React Imports
const { useEffect, useLayoutEffect, useState, useRef, useCallback } = React;

// Gsap Ticker Function
function useTicker(callback, paused) {
  useLayoutEffect(() => {
    if (!paused && callback) {
      gsap.ticker.add(callback);
    }
    return () => {
      gsap.ticker.remove(callback);
    };
  }, [callback, paused]);
}

const EMPTY = {};
function useInstance(value = {}) {
  const ref = useRef(EMPTY);
  if (ref.current === EMPTY) {
    ref.current = typeof value === "function" ? value() : value;
  }
  return ref.current;
}

// Function for Mouse Move Scale Change
function getScale(diffX, diffY) {
  const distance = Math.sqrt(Math.pow(diffX, 2) + Math.pow(diffY, 2));
  return Math.min(distance / 735, 0.35);
}

// Function For Mouse Movement Angle in Degrees
function getAngle(diffX, diffY) {
  return (Math.atan2(diffY, diffX) * 180) / Math.PI;
}

// Jelly Blob Function
const JellyBlob = () => {
  // React Refs for Jelly Blob and Text
  const jellyRef = useRef(null);
  const textRef = useRef(null);

  // Save pos and velocity Objects
  const pos = useInstance(() => ({ x: 0, y: 0 }));
  const vel = useInstance(() => ({ x: 0, y: 0 }));
  const set = useInstance();

  // Set GSAP quick setter Values on useLayoutEffect Update
  useLayoutEffect(() => {
    set.x = gsap.quickSetter(jellyRef.current, "x", "px");
    set.y = gsap.quickSetter(jellyRef.current, "y", "px");
    set.r = gsap.quickSetter(jellyRef.current, "rotate", "deg");
    set.sx = gsap.quickSetter(jellyRef.current, "scaleX");
    set.sy = gsap.quickSetter(jellyRef.current, "scaleY");
    set.rt = gsap.quickSetter(textRef.current, "rotate", "deg");
  }, []);

  // Start Animation loop
  const loop = useCallback(() => {
    // Calculate angle and scale based on velocity
    var rotation = getAngle(vel.x, vel.y); // Mouse Move Angle
    var scale = getScale(vel.x, vel.y); // Blob Squeeze Amount

    // Set GSAP quick setter Values on Loop Function
    set.x(pos.x);
    set.y(pos.y);
    set.r(rotation);
    set.sx(1 + scale);
    set.sy(1 - scale);
    set.rt(-rotation);
  }, []);

  // Run on Mouse Move
  useLayoutEffect(() => {
    // Caluclate Everything Function
    const setFromEvent = (e) => {
      // Mouse X and Y
      const x = e.clientX;
      const y = e.clientY;

      // Animate Position and calculate Velocity with GSAP
      gsap.to(pos, {
        x: x,
        y: y,
        duration: 0.95,
        ease: Expo.easeOut,
        onUpdate: () => {
          vel.x = x - pos.x;
          vel.y = y - pos.y;
        }
      });

      loop();
    };

    window.addEventListener("mousemove", setFromEvent);
    return () => {
      window.removeEventListener("mousemove", setFromEvent);
    };
  }, []);

  useTicker(loop);

  // Return UI
  return (
    <div className="container-div">
      <div ref={jellyRef} id={"jelly-id"} className="jelly-blob">
        <div ref={textRef} id={"text-id"} className="inside-text">
          Hey There, I'm Lil Blob
        </div>
      </div>
    </div>
  );
};

//APP Component for Rendering
class App extends React.Component {
  constructor(props) {
    super(props);
  }

  render() {
    return <JellyBlob />;
  }
}

ReactDOM.render(<App />, document.getElementById("root"));

              
            
!
999px

Console