<h1>
  Here is some text
  <span class="wrapper">
    <span class="item" data-animated-item>
      <svg height="20" width="20">
        <circle cx="10" cy="10" r="5" />
      </svg>
    </span>
    <span class="item" data-animated-item>
      <svg height="16" width="16">
        <circle cx="8" cy="8" r="4" />
      </svg>
    </span>
    <span class="item" data-animated-item>
      <svg height="16" width="16">
        <circle cx="8" cy="8" r="4" />
      </svg>
    </span>
    <span class="item" data-animated-item>
      <svg height="24" width="24">
        <circle cx="12" cy="12" r="6" />
      </svg>
    </span>
    <span class="animated-text">where this is magic</span>
  </span>
  and this isn't
</h1>
@import url("https://fonts.googleapis.com/css2?family=DM+Serif+Display&display=swap");

.wrapper {
  display: inline-block;
  position: relative;
}

h1 {
  font-size: clamp(2.5rem, 2vw, 4.25rem);
}

.item {
  display: block;
  position: absolute;
  opacity: 0;
  width: clamp(20px, 1.5vw, 30px);
  aspect-ratio: 1;
}

.animated-text {
  background: linear-gradient(
    to right,
    var(--purple),
    var(--violet),
    var(--pink),
    var(--purple)
  );
  background-size: 200%;
  -webkit-text-fill-color: transparent;
  -webkit-background-clip: text;
  background-clip: text;
  white-space: nowrap;
}

circle {
  fill: var(--violet);
}
:root {
  --bg: #1c1c2e;
  --purple: rgb(123, 31, 162);
  --violet: rgb(103, 58, 183);
  --pink: rgb(244, 143, 177);
}

html {
  box-sizing: border-box;
  block-size: 100%;
}

*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: inherit;
}

body {
  min-block-size: 100dvh;
  font-family: "DM Serif Display", serif;
  padding: 1rem;
  display: grid;
  place-items: center;
  background: var(--bg);
  color: white;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
const wrapper = document.querySelector(".wrapper");
const items = gsap.utils.toArray(".item");
let isHovering = false;

function animateItem(item) {
  if (isHovering) {
    gsap.fromTo(item, {
      opacity: 1,
      x: () => gsap.utils.random(0, wrapper.offsetWidth - item.offsetWidth),
      y: "random(-80, 120)"
    }, {
      y: "-=20",
      opacity: 0,
      duration: 1.5,
      delay: gsap.utils.random(0, 1),
      overwrite: "auto",
      immediateRender: false,
      onComplete: () => animateItem(item)
    });
  }
}

wrapper.addEventListener("mouseenter", () => {
  isHovering = true;
  items.forEach(animateItem);
});

wrapper.addEventListener("mouseleave", () => {
  isHovering = false;
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://unpkg.co/gsap@3/dist/gsap.min.js
  2. https://unpkg.com/gsap@3/dist/CSSRulePlugin.min.js
  3. https://assets.codepen.io/16327/CustomBounce3.min.js
  4. https://assets.codepen.io/16327/CustomEase3.min.js
  5. https://assets.codepen.io/16327/CustomWiggle3.min.js
  6. https://assets.codepen.io/16327/DrawSVGPlugin3.min.js
  7. https://unpkg.com/gsap@3/dist/Draggable.min.js
  8. https://unpkg.com/gsap@3/dist/EaselPlugin.min.js
  9. https://unpkg.com/gsap@3/dist/EasePack.min.js
  10. https://assets.codepen.io/16327/Flip.min.js
  11. https://assets.codepen.io/16327/GSDevTools3.min.js
  12. https://assets.codepen.io/16327/InertiaPlugin.min.js
  13. https://assets.codepen.io/16327/MorphSVGPlugin3.min.js
  14. https://unpkg.com/gsap@3/dist/MotionPathPlugin.min.js
  15. https://assets.codepen.io/16327/MotionPathHelper.min.js
  16. https://assets.codepen.io/16327/PhysicsPropsPlugin3.min.js
  17. https://assets.codepen.io/16327/Physics2DPlugin3.min.js
  18. https://unpkg.com/gsap@3/dist/PixiPlugin.min.js
  19. https://assets.codepen.io/16327/ScrambleTextPlugin3.min.js
  20. https://unpkg.com/gsap@3/dist/ScrollToPlugin.min.js
  21. https://unpkg.com/gsap@3/dist/ScrollTrigger.min.js
  22. https://assets.codepen.io/16327/SplitText3.min.js
  23. https://unpkg.com/gsap@3/dist/TextPlugin.min.js
  24. https://assets.codepen.io/16327/ScrollSmoother.min.js
  25. https://unpkg.com/gsap/dist/Observer.min.js