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

Packages

Add Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import or require. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

            
              <button class="btn-axe">
  <div class="axe-throw">
    <svg  viewBox="0 0 276 546" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
      <defs></defs>
      <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
          <g id="Artboard-2" transform="translate(-278.000000, -156.000000)" stroke="#000000" stroke-width="18">
              <g class="axe" transform="translate(287.000000, 165.000000)">
                  <polygon class="hilt" points="57.3867879 6.36012988 118.312965 6.36012988 118.312965 527.629292 57.3867879 527.629292"></polygon>
                  <path d="M0.377147893,67.9526343 C60.1476569,62.2056008 104.570818,54.9678324 133.64663,46.2393291 C162.459373,37.5897988 192.874943,22.4709695 224.893341,0.882841272 L224.893343,0.882844163 C225.351262,0.574095611 225.97277,0.695022895 226.281519,1.15294281 C226.292319,1.16896131 226.302653,1.18528944 226.312507,1.20190662 C236.341361,18.1132994 242.882854,30.7454525 245.936988,39.0983658 C255.311232,64.7364849 257.301189,88.5232439 257.301189,104.041505 C257.301189,119.695033 258.504374,145.209262 248.965994,177.489474 C245.934029,187.750385 238.39793,205.780278 226.357696,231.579155 L226.357655,231.579135 C226.1241,232.079578 225.529078,232.295933 225.028635,232.062379 C224.931691,232.017135 224.842635,231.956628 224.764864,231.883164 C210.287945,218.208002 199.142331,208.925849 191.328025,204.036704 C170.007774,190.697349 147.349822,186.848397 133.64663,182.981583 C112.236123,176.939893 67.8129623,170.553919 0.377147893,163.823662 L0.377147893,67.9526343 Z" id="head" class="axe-steel" fill="#FFFFFF"></path>
                  <path d="M192.818101,21.0138968 L192.818101,203.77343" class="axe-edge"></path>
              </g>
          </g>
      </g>
    </svg>
  </div>
</button>
            
          
!
            
              button {
  border: none;
  position: relative;
  width: 100px;
  height: 120px;
  cursor: pointer;
  margin: 0 auto;
  margin-top: 50px;
  display: block;

  .axe-throw {
    top: 0;
    left: 0;
    position: absolute;
  }

  svg {
    width: 100px;
    height: 120px;
    transform: rotate(0deg);
    transition: all 0.3s;

    .axe-steel,
    .axe-edge {
      stroke: #000;
      fill: #fff;
      transition: all 0.3s;
    }
  }

  .hilt {
    fill: #fff;
    transition: all 0.3s;
  }

  &:hover {
    .hilt {
      fill: #8C612B;
    }
  }

  &:focus {
    outline: none;
  }

  &[data-level="0"] {
    &.swing {
      svg {
        animation-name: swing-1;
        animation-duration: 0.85s;
      }
    }
  }

  &[data-level="1"] {
    svg {
      transform: rotate(-10deg);
    }
    &.swing {
      svg {
        animation-name: swing-1;
        animation-duration: 0.5s;
      }
    }
  }

  &[data-level="2"] {
    svg {
      transform: rotate(-50deg);
    }

    &.swing {
      svg {
        animation-name: swing-2;
        animation-duration: 0.5s;
      }
    }
  }

  &[data-level="3"] {
    svg {
      transform: rotate(-55deg);

      .axe-steel{
        stroke: #abeaef;
        fill: #abeaef;
      }
      .axe-edge{
        stroke: #B4F6FC;
      }
    }
    &.swing {
      .axe-throw {
        animation-name: fly-off;
        animation-duration: 1.45s;
      }

      svg {
        transform: rotate(0deg);
        animation-name: swing-3;
        animation-duration: 1.45s;
      }
    }
  }

  &.struggle {
    svg {
      animation-duration: 0.6s;
      animation-name: struggling;
      animation-iteration-count: infinite;
      animation-timing-function: ease-in;
    }
  }
}

@keyframes struggling {
  0% {
    transform: rotate(-55deg);
  }

  50% {
    transform: rotate(-60deg);
  }
}

@keyframes swing-1 {
  0% {
    transform: rotate(0deg);
  }

  50% {
    transform: rotate(155deg);
  }

  100% {
    transform: rotate(0deg);
  }
}

@keyframes swing-2 {
  0% {
    transform: rotate(0deg);
  }

  50% {
    transform: rotate(75deg);
  }

  100% {
    transform: rotate(0deg);
  }
}

@keyframes swing-3 {
  0% {
    transform: initial;
  }

  50% {
    transform: rotate(720deg);
  }

  90% {
    transform: rotate(0deg);
  }
}

@keyframes fly-off {
  50% {
    opacity: 0;
    transform: translate(80px);
  }

  90% {
    transform: translate(0px);
  }

  100% {
    opacity: 1;
  }
}

            
          
!
            
              let axes = document.querySelectorAll('.btn-axe');
let levelTimer = {};
let animationEvent = whichAnimationEvent();

for(let axe of axes) {
  axe.dataset.level = 0;
  axe.addEventListener('mousedown',function() {
    levelTimer = setInterval(function() {
      increaseLevel(axe)
    }, 500);
    axe.addEventListener('mouseup', function() {
      axe.classList.remove('struggle');
      axe.classList.add('swing');
      axe.addEventListener(animationEvent, animationEndCallback);
      clearInterval(levelTimer);
      
    })
  })
}

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

function animationEndCallback(event) {
    this.dataset.level = 0;
    this.removeEventListener(animationEvent, function(){animationEndCallback});
    this.classList.remove('swing');
    
}

// Function from David Walsh: http://davidwalsh.name/css-animation-callback
function whichAnimationEvent(){
    var t,
        el = document.createElement("fakeelement");

    var transitions = {
        "animation"      : "animationend",
        "OAnimation"     : "oAnimationEnd",
        "MozAnimation"   : "animationend",
        "WebkitAnimation": "webkitAnimationEnd"
    }

    for (t in transitions){
        if (el.style[t] !== undefined){
            return transitions[t];
        }
    }
}
            
          
!
999px

Console