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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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 class="title">
  <h1>GSAP MorphSVGPlugin: Click the Button</h1>
</div>
<div class="container">
  <button type="button" class="send-button">
    <span class="btn-text">Send</span> <svg id="button-icons" xmlns="http://www.w3.org/2000/svg" width="510.9" height="510.9" viewBox="0 0 510.9 510.9" role="img">
  <title>morph-button</title>
  
  <g class="circle-group">
    <path d="M255.5.5c140.7,0,255,114.2,255,255s-114.2,255-255,255S.5,396.2.5,255.5,114.7.5,255.5.5Z" class="circle" stroke="#2edb3a"/>
  </g>
  <g>
    <path d="M373.7,240.6,173.1,100.4c-16.6-10.9-41.5-10.9-55.8,1.8s-14.2,31.7,2.4,42.5h0L288.2,263.2,119.7,381.7c-16.6,10.9-16.6,29.9-2.4,42.5a49.6,49.6,0,0,0,29.7,10c9.5,0,19-2.7,26.1-8.1L373.7,285.8c8.3-5.4,13.1-13.6,13.1-22.6S382,246,373.7,240.6Z" class="arrow" stroke="#db6d5e"/>
  </g>
  <path d="M234,490.5a41.4,41.4,0,0,1-35.4-19.4L99.2,316.2a42.2,42.2,0,0,1,71.1-45.4l56.4,88.1L340.9,94.6c9.4-21.3,34.2-31.3,55.5-21.9s31.3,34.2,21.9,55.5L272.9,465.1a42.2,42.2,0,0,1-35.4,25.4Z" class="check" stroke="#96fff5"/>
</svg>
  </button>
  <div class="thankyou">
    <p>Thank you for getting in touch <br> :)</p>
  </div> 
</div>
              
            
!

CSS

              
                $main-color: purple;
$success-color: #63db41;
$bg-color:rgba(114, 94, 127,0.8);
* {
  box-sizing: border-box;
}

html {
  background: $bg-color url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/234228/app.bg.jpg) center center no-repeat;
  background-size: cover;  
}

html, body {
  width: 100%;
  height: 100vh; 
}

body{
  font-family:sans-serif;
  text-align: center;
  margin: 0;
  padding: 0;
  color: white;
  overflow: hidden;
}

.title h1 {
  font-size: 1.5rem;
  font-weight: normal;
}

.container {
	position: relative;
  width: 300px;
  height: 400px;
  margin: 0 auto;
  border: 5px solid lighten($main-color, 10);
  border-radius: 15px;
  padding: 1em;
  text-align: center;
  background-color: $bg-color;
}

.send-button {
  width: 80%; 
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5em 1em;
  border: none;
  border-radius: 5px;
  text-align: center;
  text-transform: uppercase;
  font-size: 1.3rem;
  color: white;
  background-color: $main-color;
  cursor: pointer;
  box-shadow: 0px 3px 3px 1px rgba(0,0,0,.5);
}

.send-button:hover,
.send-button:focus {
  background-color: darken($main-color, 10);
}

.send-button:active {
  background-color: darken($main-color, 10);
  box-shadow: 0px 3px 3px 1px rgba(0,0,0,.5) inset;
}

.btn-text {
  width: 80px;
  font-size: 1.5rem;
  color: white;
}

.thankyou {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0;
  visibility: hidden;
  font-size: 1.5rem;
  line-height: 1.5;
}

/* SVG Styles */
svg {
  margin-left: 6px;
  width: 50px;
  height: 50px;
}

.arrow {
  fill: white;
}

.check {
  visibility: hidden;
}

.circle {
  fill: lighten($main-color, 20);  
}
              
            
!

JS

              
                // vars
const btn = document.querySelector('.send-button'),
      circle = document.querySelector('.circle'),
      circleGroup = document.querySelector('.circle-group'),
      arrow = document.querySelector('.arrow'),
      btnText = document.querySelector('.btn-text'),
      thankYou = document.querySelector('.thankyou'),
      master = new TimelineMax({paused: true});

// Animate the left arrow out of the screen
function sendMessage() {
  const tl = new TimelineMax();
  tl.add('startSending')
    .to(arrow, 0.5, {
      autoAlpha: 0
  });
  return tl;
} 

// Animate the circle to indicate that the 
// input is being sent and change the 
// text on the button accordingly
function loader() {
  const tl = new TimelineMax({
    repeat: 4,
    onStart: function() {
      btnText.innerHTML = '✈';
    }
  });
  
  tl.add('startLoading')
    .from(circleGroup, 0.5, {
      transformOrigin: '50% 50%',  
      scaleY: 0,
      scaleX: 0,
      ease: Power0.easeNone
  });
  return tl;
}

// Morph the circle into the check icon 
// to indicate the input has been 
// received successfully. 
function morphing() {
  const tl = new TimelineMax();
  tl.add('startMorph')
    .to('.circle', 0.5, {
      morphSVG: '.check',
      fill: '#63db41',
      // Change button text accordingly 
      // at the end of the animation
      onComplete: function() {
        btnText.innerHTML = 'Sent!';
      }
  });
  return tl;
}

// Final animation to remove the button and 
// have the thank you message appear
function finish() {
  const tl = new TimelineMax();
    tl.add('closeButton')
      .to(btn, 0.3, {
        scaleY: 0,
        ease: Circ.easeIn
    }, 'closeButton+=2')
      .to(btn, 0.2, {
        autoAlpha: 0
    })
    .fromTo(thankYou, 0.5, {
        scaleY: 5
    }, {
       autoAlpha: 1,
       scaleY: 1,
       ease: Back.easeOut
    });
  return tl;
}

// Use a master timeline to call the animation 
// functions
master.add(sendMessage())
      .add(loader())
      .add(morphing())
      .add(finish());

// All the functionality above gets triggered 
// when the send button is clicked
btn.addEventListener('click', function() {
  master.restart();
});
              
            
!
999px

Console