Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <header>
  <h1>SVG link effects with GSAP</h1>
</header>

<div class="wrapper">
  <a href="#" id="wave-link">
    <span>Click me</span>
    <svg height="100%" width="100%" xmlns="http://www.w3.org/2000/svg" id="ease-link-svg">
      <rect x="0" y="-44" width="3" height="44" />
      <rect x="3" y="-44" width="3" height="44" />
      <rect x="6" y="-44" width="3" height="44" />
      <rect x="9" y="-44" width="3" height="44" />
      <rect x="12" y="-44" width="3" height="44" />
      <rect x="15" y="-44" width="3" height="44" />
      <rect x="18" y="-44" width="3" height="44" />
      <rect x="21" y="-44" width="3" height="44" />
      <rect x="24" y="-44" width="3" height="44" />
      <rect x="27" y="-44" width="3" height="44" />
      <rect x="30" y="-44" width="3" height="44" />
      <rect x="33" y="-44" width="3" height="44" />
      <rect x="36" y="-44" width="3" height="44" />
      <rect x="39" y="-44" width="3" height="44" />
      <rect x="42" y="-44" width="3" height="44" />
      <rect x="45" y="-44" width="3" height="44" />
      <rect x="48" y="-44" width="3" height="44" />
      <rect x="51" y="-44" width="3" height="44" />
      <rect x="54" y="-44" width="3" height="44" />
      <rect x="57" y="-44" width="3" height="44" />
      <rect x="60" y="-44" width="3" height="44" />
      <rect x="63" y="-44" width="3" height="44" />
      <rect x="66" y="-44" width="3" height="44" />
      <rect x="69" y="-44" width="3" height="44" />
      <rect x="72" y="-44" width="3" height="44" />
      <rect x="75" y="-44" width="3" height="44" />
      <rect x="78" y="-44" width="3" height="44" />
      <rect x="81" y="-44" width="3" height="44" />
      <rect x="84" y="-44" width="3" height="44" />
      <rect x="87" y="-44" width="3" height="44" />
      <rect x="90" y="-44" width="3" height="44" />
      <rect x="93" y="-44" width="3" height="44" />
      <rect x="96" y="-44" width="3" height="44" />
      <rect x="99" y="-44" width="3" height="44" />
      <rect x="102" y="-44" width="3" height="44" />
      <rect x="105" y="-44" width="3" height="44" />
      <rect x="108" y="-44" width="3" height="44" />
    </svg>
  </a>

  <a href="#" id="random-elastic-link">
    <span>Click me</span>
    <svg height="100%" width="100%" xmlns="http://www.w3.org/2000/svg">
      <rect x="0" y="-44" width="3" height="44" />
      <rect x="3" y="-44" width="3" height="44" />
      <rect x="6" y="-44" width="3" height="44" />
      <rect x="9" y="-44" width="3" height="44" />
      <rect x="12" y="-44" width="3" height="44" />
      <rect x="15" y="-44" width="3" height="44" />
      <rect x="18" y="-44" width="3" height="44" />
      <rect x="21" y="-44" width="3" height="44" />
      <rect x="24" y="-44" width="3" height="44" />
      <rect x="27" y="-44" width="3" height="44" />
      <rect x="30" y="-44" width="3" height="44" />
      <rect x="33" y="-44" width="3" height="44" />
      <rect x="36" y="-44" width="3" height="44" />
      <rect x="39" y="-44" width="3" height="44" />
      <rect x="42" y="-44" width="3" height="44" />
      <rect x="45" y="-44" width="3" height="44" />
      <rect x="48" y="-44" width="3" height="44" />
      <rect x="51" y="-44" width="3" height="44" />
      <rect x="54" y="-44" width="3" height="44" />
      <rect x="57" y="-44" width="3" height="44" />
      <rect x="60" y="-44" width="3" height="44" />
      <rect x="63" y="-44" width="3" height="44" />
      <rect x="66" y="-44" width="3" height="44" />
      <rect x="69" y="-44" width="3" height="44" />
      <rect x="72" y="-44" width="3" height="44" />
      <rect x="75" y="-44" width="3" height="44" />
      <rect x="78" y="-44" width="3" height="44" />
      <rect x="81" y="-44" width="3" height="44" />
      <rect x="84" y="-44" width="3" height="44" />
      <rect x="87" y="-44" width="3" height="44" />
      <rect x="90" y="-44" width="3" height="44" />
      <rect x="93" y="-44" width="3" height="44" />
      <rect x="96" y="-44" width="3" height="44" />
      <rect x="99" y="-44" width="3" height="44" />
      <rect x="102" y="-44" width="3" height="44" />
      <rect x="105" y="-44" width="3" height="44" />
      <rect x="108" y="-44" width="3" height="44" />
    </svg>
  </a>

  <a href="#" id="cascade-link">
    <span>Click me</span>
    <svg height="100%" width="100%" xmlns="http://www.w3.org/2000/svg">
      <rect x="0" y="-44" width="3" height="44" />
      <rect x="3" y="-44" width="3" height="44" />
      <rect x="6" y="-44" width="3" height="44" />
      <rect x="9" y="-44" width="3" height="44" />
      <rect x="12" y="-44" width="3" height="44" />
      <rect x="15" y="-44" width="3" height="44" />
      <rect x="18" y="-44" width="3" height="44" />
      <rect x="21" y="-44" width="3" height="44" />
      <rect x="24" y="-44" width="3" height="44" />
      <rect x="27" y="-44" width="3" height="44" />
      <rect x="30" y="-44" width="3" height="44" />
      <rect x="33" y="-44" width="3" height="44" />
      <rect x="36" y="-44" width="3" height="44" />
      <rect x="39" y="-44" width="3" height="44" />
      <rect x="42" y="-44" width="3" height="44" />
      <rect x="45" y="-44" width="3" height="44" />
      <rect x="48" y="-44" width="3" height="44" />
      <rect x="51" y="-44" width="3" height="44" />
      <rect x="54" y="-44" width="3" height="44" />
      <rect x="57" y="-44" width="3" height="44" />
      <rect x="60" y="-44" width="3" height="44" />
      <rect x="63" y="-44" width="3" height="44" />
      <rect x="66" y="-44" width="3" height="44" />
      <rect x="69" y="-44" width="3" height="44" />
      <rect x="72" y="-44" width="3" height="44" />
      <rect x="75" y="-44" width="3" height="44" />
      <rect x="78" y="-44" width="3" height="44" />
      <rect x="81" y="-44" width="3" height="44" />
      <rect x="84" y="-44" width="3" height="44" />
      <rect x="87" y="-44" width="3" height="44" />
      <rect x="90" y="-44" width="3" height="44" />
      <rect x="93" y="-44" width="3" height="44" />
      <rect x="96" y="-44" width="3" height="44" />
      <rect x="99" y="-44" width="3" height="44" />
      <rect x="102" y="-44" width="3" height="44" />
      <rect x="105" y="-44" width="3" height="44" />
      <rect x="108" y="-44" width="3" height="44" />
    </svg>
  </a>

  <a href="#" id="random-step-link">
    <span>Click me</span>
    <svg height="100%" width="100%" xmlns="http://www.w3.org/2000/svg">
      <rect x="0" y="-44" width="3" height="44" />
      <rect x="3" y="-44" width="3" height="44" />
      <rect x="6" y="-44" width="3" height="44" />
      <rect x="9" y="-44" width="3" height="44" />
      <rect x="12" y="-44" width="3" height="44" />
      <rect x="15" y="-44" width="3" height="44" />
      <rect x="18" y="-44" width="3" height="44" />
      <rect x="21" y="-44" width="3" height="44" />
      <rect x="24" y="-44" width="3" height="44" />
      <rect x="27" y="-44" width="3" height="44" />
      <rect x="30" y="-44" width="3" height="44" />
      <rect x="33" y="-44" width="3" height="44" />
      <rect x="36" y="-44" width="3" height="44" />
      <rect x="39" y="-44" width="3" height="44" />
      <rect x="42" y="-44" width="3" height="44" />
      <rect x="45" y="-44" width="3" height="44" />
      <rect x="48" y="-44" width="3" height="44" />
      <rect x="51" y="-44" width="3" height="44" />
      <rect x="54" y="-44" width="3" height="44" />
      <rect x="57" y="-44" width="3" height="44" />
      <rect x="60" y="-44" width="3" height="44" />
      <rect x="63" y="-44" width="3" height="44" />
      <rect x="66" y="-44" width="3" height="44" />
      <rect x="69" y="-44" width="3" height="44" />
      <rect x="72" y="-44" width="3" height="44" />
      <rect x="75" y="-44" width="3" height="44" />
      <rect x="78" y="-44" width="3" height="44" />
      <rect x="81" y="-44" width="3" height="44" />
      <rect x="84" y="-44" width="3" height="44" />
      <rect x="87" y="-44" width="3" height="44" />
      <rect x="90" y="-44" width="3" height="44" />
      <rect x="93" y="-44" width="3" height="44" />
      <rect x="96" y="-44" width="3" height="44" />
      <rect x="99" y="-44" width="3" height="44" />
      <rect x="102" y="-44" width="3" height="44" />
      <rect x="105" y="-44" width="3" height="44" />
      <rect x="108" y="-44" width="3" height="44" />
    </svg>
  </a>

  <a href="#" id="alternating-elastic-link">
    <span>Click me</span>
    <svg height="100%" width="100%" xmlns="http://www.w3.org/2000/svg">
      <rect x="0" y="-44" width="3" height="44" />
      <rect x="3" y="44" width="3" height="44" />
      <rect x="6" y="-44" width="3" height="44" />
      <rect x="9" y="44" width="3" height="44" />
      <rect x="12" y="-44" width="3" height="44" />
      <rect x="15" y="44" width="3" height="44" />
      <rect x="18" y="-44" width="3" height="44" />
      <rect x="21" y="44" width="3" height="44" />
      <rect x="24" y="-44" width="3" height="44" />
      <rect x="27" y="44" width="3" height="44" />
      <rect x="30" y="-44" width="3" height="44" />
      <rect x="33" y="44" width="3" height="44" />
      <rect x="36" y="-44" width="3" height="44" />
      <rect x="39" y="44" width="3" height="44" />
      <rect x="42" y="-44" width="3" height="44" />
      <rect x="45" y="44" width="3" height="44" />
      <rect x="48" y="-44" width="3" height="44" />
      <rect x="51" y="44" width="3" height="44" />
      <rect x="54" y="-44" width="3" height="44" />
      <rect x="57" y="44" width="3" height="44" />
      <rect x="60" y="-44" width="3" height="44" />
      <rect x="63" y="44" width="3" height="44" />
      <rect x="66" y="-44" width="3" height="44" />
      <rect x="69" y="44" width="3" height="44" />
      <rect x="72" y="-44" width="3" height="44" />
      <rect x="75" y="44" width="3" height="44" />
      <rect x="78" y="-44" width="3" height="44" />
      <rect x="81" y="44" width="3" height="44" />
      <rect x="84" y="-44" width="3" height="44" />
      <rect x="87" y="44" width="3" height="44" />
      <rect x="90" y="-44" width="3" height="44" />
      <rect x="93" y="44" width="3" height="44" />
      <rect x="96" y="-44" width="3" height="44" />
      <rect x="99" y="44" width="3" height="44" />
      <rect x="102" y="-44" width="3" height="44" />
      <rect x="105" y="44" width="3" height="44" />
      <rect x="108" y="-44" width="3" height="44" />
    </svg>
  </a>

  <a href="#" id="alternating-link">
    <span>Click me</span>
    <svg height="100%" width="100%" xmlns="http://www.w3.org/2000/svg">
      <rect x="0" y="-44" width="3" height="44" />
      <rect x="3" y="44" width="3" height="44" />
      <rect x="6" y="-44" width="3" height="44" />
      <rect x="9" y="44" width="3" height="44" />
      <rect x="12" y="-44" width="3" height="44" />
      <rect x="15" y="44" width="3" height="44" />
      <rect x="18" y="-44" width="3" height="44" />
      <rect x="21" y="44" width="3" height="44" />
      <rect x="24" y="-44" width="3" height="44" />
      <rect x="27" y="44" width="3" height="44" />
      <rect x="30" y="-44" width="3" height="44" />
      <rect x="33" y="44" width="3" height="44" />
      <rect x="36" y="-44" width="3" height="44" />
      <rect x="39" y="44" width="3" height="44" />
      <rect x="42" y="-44" width="3" height="44" />
      <rect x="45" y="44" width="3" height="44" />
      <rect x="48" y="-44" width="3" height="44" />
      <rect x="51" y="44" width="3" height="44" />
      <rect x="54" y="-44" width="3" height="44" />
      <rect x="57" y="44" width="3" height="44" />
      <rect x="60" y="-44" width="3" height="44" />
      <rect x="63" y="44" width="3" height="44" />
      <rect x="66" y="-44" width="3" height="44" />
      <rect x="69" y="44" width="3" height="44" />
      <rect x="72" y="-44" width="3" height="44" />
      <rect x="75" y="44" width="3" height="44" />
      <rect x="78" y="-44" width="3" height="44" />
      <rect x="81" y="44" width="3" height="44" />
      <rect x="84" y="-44" width="3" height="44" />
      <rect x="87" y="44" width="3" height="44" />
      <rect x="90" y="-44" width="3" height="44" />
      <rect x="93" y="44" width="3" height="44" />
      <rect x="96" y="-44" width="3" height="44" />
      <rect x="99" y="44" width="3" height="44" />
      <rect x="102" y="-44" width="3" height="44" />
      <rect x="105" y="44" width="3" height="44" />
      <rect x="108" y="-44" width="3" height="44" />
    </svg>
  </a>

  <a href="#" id="step-link-horizontal">
    <span>Click me</span>
    <svg height="100%" width="100%" xmlns="http://www.w3.org/2000/svg">
      <rect x="0" y="-44" width="3" height="44" />
      <rect x="3" y="-44" width="3" height="44" />
      <rect x="6" y="-44" width="3" height="44" />
      <rect x="9" y="-44" width="3" height="44" />
      <rect x="12" y="-44" width="3" height="44" />
      <rect x="15" y="-44" width="3" height="44" />
      <rect x="18" y="-44" width="3" height="44" />
      <rect x="21" y="-44" width="3" height="44" />
      <rect x="24" y="-44" width="3" height="44" />
      <rect x="27" y="-44" width="3" height="44" />
      <rect x="30" y="-44" width="3" height="44" />
      <rect x="33" y="-44" width="3" height="44" />
      <rect x="36" y="-44" width="3" height="44" />
      <rect x="39" y="-44" width="3" height="44" />
      <rect x="42" y="-44" width="3" height="44" />
      <rect x="45" y="-44" width="3" height="44" />
      <rect x="48" y="-44" width="3" height="44" />
      <rect x="51" y="-44" width="3" height="44" />
      <rect x="54" y="-44" width="3" height="44" />
      <rect x="57" y="-44" width="3" height="44" />
      <rect x="60" y="-44" width="3" height="44" />
      <rect x="63" y="-44" width="3" height="44" />
      <rect x="66" y="-44" width="3" height="44" />
      <rect x="69" y="-44" width="3" height="44" />
      <rect x="72" y="-44" width="3" height="44" />
      <rect x="75" y="-44" width="3" height="44" />
      <rect x="78" y="-44" width="3" height="44" />
      <rect x="81" y="-44" width="3" height="44" />
      <rect x="84" y="-44" width="3" height="44" />
      <rect x="87" y="-44" width="3" height="44" />
      <rect x="90" y="-44" width="3" height="44" />
      <rect x="93" y="-44" width="3" height="44" />
      <rect x="96" y="-44" width="3" height="44" />
      <rect x="99" y="-44" width="3" height="44" />
      <rect x="102" y="-44" width="3" height="44" />
      <rect x="105" y="-44" width="3" height="44" />
      <rect x="108" y="-44" width="3" height="44" />
    </svg>
  </a>
</div>
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css2?family=Bebas+Neue&display=swap");
@import url("https://fonts.googleapis.com/css2?family=Lexend+Deca:wght@300&display=swap");

html,
body {
  height: 100%;
}

body {
  background-color: #3d3e4a;
  color: #b6bbc2;
  display: flex;
  justify-content: center;
  font-family: "IBM Plex Mono", monospace;
  font-weight: 300;
  font-style: normal;
  font-size: 12px;
  flex-direction: column;
  margin: 0;
}

header {
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: rgba(0, 0, 0, 0.5);
  padding: 20px 15px;
  margin-bottom: 25px;
  width: 100%;
}

h1 {
  color: #76b3fa;
  font-size: 24px;
  font-family: "Lexend Deca", sans-serif;
  font-weight: 300;
  margin-top: 0;
  margin-bottom: 5px;
}

.wrapper {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  margin: 25px 0;
}

svg {
  rect {
    fill: #ff4066;
    transition: fill 300ms ease-in-out;
  }
}

a {
  align-items: center;
  background-color: rgba(118, 180, 250, 0.2);
  border-radius: 5px;
  color: #ffffff;
  display: flex;
  justify-content: center;
  font-family: "Bebas Neue", sans-serif;
  font-size: 28px;
  font-style: normal;
  font-weight: 400;
  height: 44px;
  margin: 10px 5px;
  overflow: hidden;
  position: relative;
  text-decoration: none;
  user-select: none;
  width: 111px;

  span {
    display: inline-block;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    margin-top: 2px;
    position: absolute;
    white-space: nowrap;
  }
}

              
            
!

JS

              
                class SvgLinkEffect {
  constructor(effect) {
    if (effect.config.random) {
      this.randomizeArray(effect.nodes);
    }

    effect.element.addEventListener("click", () => {
      let reverse = effect.element.classList.contains("active") ? true : false;
      effect.element.classList.toggle("active");
      effect.handler(effect.nodes, effect.config, reverse);
    });
  }

  randomizeArray(array) {
    for (let i = array.length - 1; i > 0; i--) {
      const j = Math.floor(Math.random() * (i + 1));
      [array[i], array[j]] = [array[j], array[i]];
    }
  }
}

const svgBounceEffect = (nodes, config, reverse) => {
  nodes.forEach((node, index) => {
    const { duration, ease, y1, y2, offset } = config;
    setTimeout(() => {
      if (reverse) {
        gsap.to(node, {
          duration: duration,
          ease: ease,
          y: y1
        });
      } else {
        gsap.to(node, {
          duration: duration,
          ease: ease,
          y: y2
        });
      }
    }, index * offset);
  });
};

const svgAlertnatingEffect = (nodes, config, reverse) => {
  nodes.forEach((node, index) => {
    const { duration, ease, offset } = config;
    setTimeout(() => {
      if (reverse) {
        gsap.to(node, {
          duration: duration,
          ease: ease,
          y: index % 2 === 0 ? -44 : 44
        });
      } else {
        gsap.to(node, {
          duration: duration,
          ease: ease,
          y: index % 2 === 0 ? 44 : -44
        });
      }
    }, index * offset);
  });
};

document.addEventListener("DOMContentLoaded", (event) => {
  const waveLink = document.getElementById("wave-link");
  const waveLinkEffect = {
    element: waveLink,
    handler: svgBounceEffect,
    nodes: [...waveLink.querySelectorAll("rect")],
    config: {
      offset: 10,
      duration: 1,
      random: false,
      ease: "elastic.out(0.8, 0.3)",
      y1: -20,
      y2: 44
    }
  };

  const randomElasticLink = document.getElementById("random-elastic-link");
  const randomElasticLinkEffect = {
    element: randomElasticLink,
    handler: svgBounceEffect,
    nodes: [...randomElasticLink.querySelectorAll("rect")],
    config: {
      offset: 10,
      duration: 1,
      random: true,
      ease: "elastic.out(0.8, 0.3)",
      y1: -20,
      y2: 44
    }
  };

  const cascadeLink = document.getElementById("cascade-link");
  const cascadeLinkEffect = {
    element: cascadeLink,
    handler: svgBounceEffect,
    nodes: [...cascadeLink.querySelectorAll("rect")],
    config: {
      offset: 10,
      duration: 1,
      random: true,
      ease: "expo.out",
      y1: -20,
      y2: 44
    }
  };

  const randomStepLink = document.getElementById("random-step-link");
  const randomStepLinkEffect = {
    element: randomStepLink,
    handler: svgBounceEffect,
    nodes: [...randomStepLink.querySelectorAll("rect")],
    config: {
      offset: 10,
      duration: 0.8,
      random: true,
      ease: "steps(5)",
      y1: -20,
      y2: 44
    }
  };

  const stepLinkHorizontal = document.getElementById("step-link-horizontal");
  const stepLinkHorizontalEffect = {
    element: stepLinkHorizontal,
    handler: svgBounceEffect,
    nodes: [...stepLinkHorizontal.querySelectorAll("rect")],
    config: {
      offset: 5,
      duration: 0.25,
      random: false,
      ease: "steps(10)",
      y1: -20,
      y2: 44
    }
  };

  const alternatingLink = document.getElementById("alternating-link");
  const alternatingLinkEffect = {
    element: alternatingLink,
    handler: svgAlertnatingEffect,
    nodes: [...alternatingLink.querySelectorAll("rect")],
    config: {
      offset: 5,
      duration: 1,
      random: false,
      ease: "expo.out"
    }
  };

  const alternatingElasticLink = document.getElementById(
    "alternating-elastic-link"
  );
  const alternatingElasticLinkEffect = {
    element: alternatingElasticLink,
    handler: svgAlertnatingEffect,
    nodes: [...alternatingElasticLink.querySelectorAll("rect")],
    config: {
      offset: 10,
      duration: 1,
      random: false,
      ease: "elastic.out(0.8, 0.3)"
    }
  };

  new SvgLinkEffect(waveLinkEffect);
  new SvgLinkEffect(randomElasticLinkEffect);
  new SvgLinkEffect(cascadeLinkEffect);
  new SvgLinkEffect(randomStepLinkEffect);
  new SvgLinkEffect(stepLinkHorizontalEffect);
  new SvgLinkEffect(alternatingLinkEffect);
  new SvgLinkEffect(alternatingElasticLinkEffect);
});

              
            
!
999px

Console