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

              
                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: "JELLY Blob!";
  text-align: center;
  width: 100%;
  line-height: 100vh;
  background-blend-mode: overlay;
  mix-blend-mode: overlay;
  color: blue;
  position: absolute;
  font-size: 220px;
  font-weight: 700;
}
/* Main Background Div */
.container-div {
  width: 100%;
}
/* Jelly Blob Div */
.jelly-blob {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 400px;
  height: 400px;
  mix-blend-mode: difference;
  background-color: lightcoral;
  border-radius: 50%;
  transform-origin: center center;
  will-change: width, height, transform, border;
  z-index: 999;
  pointer-events: none;
}
/* Text Inside Jelly Blob */
.inside-text {
  opacity: 1;
  color: white;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  line-height: 400px;
  text-align: center;
  vertical-align: middle;
  transform-origin: center center;
}

              
            
!

JS

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

// Jelly Blob Function
const JellyBlob = () => {
    
  // Import React and UseState and UseEffect
  const { useEffect, useState } = React;

  // 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 / 650, 0.25);
  }

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

  // Save pos and velocity Objects
  const pos = { x: 0, y: 0 };
  const vel = { x: 0, y: 0 };

  // Loop not Started Yet
  let loopStarted = false;

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

    // Animate Pos Object and calculate Vel Object Velocity
    gsap.to(pos, {
      x: x,
      y: y,
      ease: "expo.out",
      duration: 0.55,
      onUpdate: () => {
        vel.x = x - pos.x;
        vel.y = y - pos.y;
      },
    });

    // Start loop
    if (!loopStarted) {
      loop();
      loopStarted = true;
    }
  };

  // Start Animation loop
  const loop = () => {
    // Jelly Shape To Be Modified
    const shape = document.getElementById("jelly-id");
    // Inside Text to be Modified
    const text = document.getElementById("text-id");

    // Calculate angle and scale based on velocity
    var rotation = getAngle(vel.x, vel.y);
    var scale = getScale(vel.x, vel.y);

    // Set transform data to Jelly Blob
    gsap.to(shape, {
      x: pos.x - 200,
      y: pos.y - 200,
      rotation: rotation + "_short",
      scaleX: 1 + scale,
      scaleY: 1 - scale,
    });
    gsap.to(text, {
      rotation: -rotation + "_short",
    });
    // Animation Frame for Loop Function
    requestAnimationFrame(loop);
  };

  // Run on Mouse Move
  useEffect(() => {
    window.addEventListener("mousemove", setFromEvent);

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

  return (
    <div className="container-div">
      <div id={"jelly-id"} className="jelly-blob">
        <div id={"text-id"} className="inside-text">
          Hello Friends!
        </div>
      </div>
    </div>
  );
};

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

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

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

              
            
!
999px

Console