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 class="container">
  <div class="heart-wrap">
    <div class="heart">
      <div class="tank"></div>
      <svg class="curve" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto">
        <defs>
          <path id="gentle-wave" d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z" />
        </defs>
        <g>
          <use xlink:href="#gentle-wave" x="48" y="0" fill="rgba(103, 130, 191, 0.5)" />
          <use xlink:href="#gentle-wave" x="48" y="1" fill="rgba(103, 130, 191, 0.3)" />
          <use xlink:href="#gentle-wave" x="48" y="2" fill="rgba(103, 130, 191, 1)" />
        </g>
      </svg>
    </div>
  </div>
</div>
<svg>
  <clipPath id="myPath" clipPathUnits="objectBoundingBox">
<!--     <path d="M0.498,1 s0.243,-0.102,0.394,-0.323 S1,0.14,0.864,0.033 S0.498,0.141,0.498,0.141 S0.291,-0.08,0.124,0.031 s-0.159,0.434,-0.021,0.646 S0.498,1,0.498,1" /> -->
    <path d="M0.373,0.967 S0.616,0.866,0.768,0.644 S0.912,0.107,0.739,0 S0.373,0.108,0.373,0.108 S0.166,-0.113,0,-0.002 S-0.159,0.432,-0.021,0.644 S0.373,0.967,0.373,0.967"></path>
  </clipPath>
</svg>


              
            
!

CSS

              
                /* 
Wave svg credits - https://codepen.io/goodkatz/pen/LYPGxQz
*/

:root {
  --dim-x: 80px;
  --dim-y: 70px;
  --cruve-height: 20px; 
}
 
* {
  border: 0;
  margin: 0;
  box-sizing: border-box;
}

.container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  background: white;
}

#myPath {
  path {
    transform: translate(0.125px, 0.033px); 
  }
}

.heart-wrap {
  cursor: pointer;
  perspective: 200px;
  filter: drop-shadow(0px 10px 10px rgba(174, 196, 238, 0.5));
}

.heart {
  position: relative;
  height: var(--dim-y);
  width: var(--dim-x);
  overflow: hidden;
  clip-path: url(#myPath);
  background-image: radial-gradient(#c9d8f5 60%, #afc4ee);
}

.tank {
  position: absolute;
  bottom: 0;
  height: 0;
  width: var(--dim-x);
  background-color: rgb(103, 130, 191);
  z-index: 5;
}

.curve {
  position: absolute;
  bottom: calc(-1 * var(--cruve-height));
  width: var(--dim-x);
  height: var(--cruve-height);
  
  use {
    animation: move 2s cubic-bezier(.55,.5,.45,.5) infinite;
  }
  
  use:nth-child(1) {
    animation-duration: 3s;
  }
  use:nth-child(2) {
    animation-duration: 4s;
  }
  use:nth-child(3) {
    animation-duration: 2s;
  }
}

@keyframes move {
  0% {
    transform: translateX(-90px);
  }
  100% {
    transform: translateX(85px);
  }
}



              
            
!

JS

              
                window.onload = function() {
  let pumpLevels = [15, 20, 25, 0];
  let tankLevels = [25, 45, 70, -20];
  let counter = 0;
  let isAnimating = false;
  
  function pumpHeart() {
    if(isAnimating) {
      return;
    }
    
    isAnimating = true;
    //forward
    gsap.to('.heart', {
      translateZ: pumpLevels[counter], 
      duration: 0.5
    });
    
    gsap.to(".curve", {
      bottom: tankLevels[counter],
      transformOrigin: "bottom",
      scaleY: 1,
      duration: 0.5
    })
      gsap.to(".tank", {
      height: counter === 3 ? 0 : tankLevels[counter],
      duration: 0.5
    })
    
    //reverse
    gsap.to(".curve", {
      delay: 0.6,
      bottom: tankLevels[counter],
      transformOrigin: "bottom",
      scaleY: 0.5,
      duration: 0.5
    });
    
    gsap.to('.heart', {
      delay: 0.6,
      translateZ: 0,
      duration: 0.25,
      onComplete: function() {
        isAnimating = false;
      }
    })
    
    if(++counter > 3) counter = 0;
  }
  
  let heart = document.getElementsByClassName('heart')[0];
  heart.addEventListener("click", pumpHeart);
}
              
            
!
999px

Console