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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              <button class="btn-heart">
  <svg  viewBox="0 0 512 448" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <!-- Generator: Sketch 49.3 (51167) - http://www.bohemiancoding.com/sketch -->
    <desc>Created with Sketch.</desc>
    <defs>
        <linearGradient class="hide" x1="50%" y1="-21.5942912%" x2="50%" y2="0%" id="linearGradient-1">
            <stop stop-color="#FFFFFF" stop-opacity="1" offset="100%"></stop>
            <stop stop-color="#FF0000" stop-opacity="1" offset="100%"></stop>
            <animate attributeName="y2" dur="0.3s" values="100%; 0%;" begin="" repeatCount="1" />
        </linearGradient>
        <linearGradient class="hide" x1="50%" y1="-30.0644368%" x2="50%" y2="0%" id="linearGradient-2">
            <stop stop-color="#FFFFFF" stop-opacity="1" offset="100%"></stop>
            <stop stop-color="#FF0000" stop-opacity="1" offset="100%"></stop>
          <animate attributeName="y2" dur="0.3s" values="100%; 0%;" begin="" repeatCount="1" />
        </linearGradient>
      
        <linearGradient class="hide" x1="50%" y1="0%" x2="50%" y2="1%" id="linearGradient-3">
            <stop stop-color="#FFFFFF" stop-opacity="1" offset="100%"></stop>
            <stop stop-color="#FF0000" stop-opacity="1" offset="100%"></stop>
          <animate attributeName="y2" dur="0.3s" values="100%; 1%;" begin="" repeatCount="1" />
        </linearGradient>
    </defs>
    <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
        <g id="heart" transform="translate(-1.000000, 0.000000)">
            <polygon class="fill-level-1" fill="url(#linearGradient-1)" points="128.136323 282.95572 387.88558 281.783386 256.767133 417.885683"></polygon>
            <polygon class="fill-level-2" fill="url(#linearGradient-2)" points="17.1172143 167.211056 499.402216 165 387.831252 282.328569 127.809403 283.983181"></polygon>
            <path d="M45.0082871,36.0388749 L176.752932,22.3597348 L256.988256,108.171749 L333.375846,20.501156 L469.879406,36.0388749 L499,166 L27.3527415,167.289212 C28.0622018,144.172911 29.1430368,127.066559 30.5952467,115.970155 C32.0474565,104.873751 36.8518033,78.2299911 45.0082871,36.0388749 Z" class="fill-level-3" fill="url(#linearGradient-3)"></path>
            <path d="M463.3,30.7 C408.8,-15.7 327.3,-8 276.7,44.2 L257,64.6 L237.3,44.3 C196.5,2.1 114.2,-23.3 50.7,30.7 C-12.1,84.3 -15.4,180.5 40.8,238.5 L234.3,438.3 C240.5,444.7 248.7,448 256.9,448 C265.1,448 273.3,444.8 279.5,438.3 L473,238.5 C529.4,180.5 526.1,84.3 463.3,30.7 Z M450.2,216.3 L257.4,416.1 L63.8,216.3 C25.4,176.7 17.4,101.2 71.5,55.1 C126.3,8.3 190.7,42.2 214.3,66.6 L257,110.7 L299.7,66.6 C322.9,42.6 387.9,8.6 442.5,55.1 C496.5,101.1 488.6,176.6 450.2,216.3 Z" class="heart-outline" fill="#000000" fill-rule="nonzero"></path>
        </g>
    </g>
</svg>
</button>
            
          
!

CSS

            
              $red: red;

.hide{
  display:none;
}

.heart-outline,
.fill-level{
  transition: all 0.2s;
  transition-timing-function: ease;
}

.btn-heart{
  background: transparent;
  border: none;
  outline: none;
  cursor:pointer;
  transform: rotate(0deg);
  transition: all 5s;
  transition-timing-function: ease;
  width: 90px;
  margin: 20px auto;
  display :block;
  svg{
    width: 90px;
  }
  &:hover{ 
    .heart-outline{
      fill: $red;
    }
  }
}

.struggle{
  animation-duration: 1s;
  animation-name: struggling;
  animation-iteration-count: infinite;
  animation-timing-function: ease;
}

@keyframes struggling {
  0%{
    transform: rotate(0deg);
  }
  
  16%{
    transform: rotate(15deg);
  }
  
  33%{
    transform: rotate(-15deg);
  }
  
  50% {
    transform: rotate(0deg);
  }
}

            
          
!

JS

            
              let hearts = document.querySelectorAll('.btn-heart');
let levelTimer = {};
for(let heart of hearts){
  heart.dataset.level = 0;
  heart.addEventListener('mousedown',function() {
    levelTimer = setInterval(function() {
      increaseHeartLevel(heart)
    }, 500);
    heart.addEventListener('mouseup', function() {
      heart.classList.remove('struggle');
      hideBlood(heart);
      clearInterval(levelTimer);
      heart.dataset.level = 0;
    })
  })
}

function increaseHeartLevel(heart) {
  var level = parseInt(heart.dataset.level, 10);
  if(level <  3) {
   heart.dataset.level = level + 1;
    animateBlood(heart);
  } else {
    heart.classList.add('struggle');
    clearInterval(levelTimer);
  }
}

function animateBlood(heart) {
  var level = parseInt(heart.dataset.level, 10);
  const bloodLevel = heart.querySelector(`#linearGradient-${level}`);
  var newAnimate = bloodLevel.querySelector('animate');
  newAnimate.setAttribute('begin', '0s');
  newAnimate.beginElement();
  bloodLevel.classList.remove('hide');
}

function hideBlood(heart){
  for(let i= 1; i <= 3; i++){
    const bloodLevel = heart.querySelector(`#linearGradient-${i}`);
    var newAnimate = bloodLevel.querySelector('animate');
    newAnimate.setAttribute('begin', '');
    bloodLevel.classList.add('hide');
  }
}

            
          
!
999px

Console