cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <div style="width:0;height:0;overflow:hidden;">
          <svg>
            <linearGradient id="btn-grad" x1="0%" y1="-20%" x2="250%" y2="20%">
              <stop offset="0%" style="stop-color:#FD8BA9;stop-opacity:1" />
              <stop offset="25%" style="stop-color:#9A94E8;stop-opacity:1" />
              <stop offset="50%" style="stop-color:#2EDBF8;stop-opacity:1" />
              <stop offset="75%" style="stop-color:#F5F1C8;stop-opacity:1"/>
              <stop offset="100%" style="stop-color:#B1E9F9;stop-opacity:1" />
            </linearGradient>
  </svg>
</div>

<svg width="0" height="0" id="morph-button-states" preserveAspectRatio="none" viewBox="0 0 105.45 53.14">
<path class="default" d="M82.7,46.1h-60c-11,0-20-9-20-20c0-11,8.9-20,20-20h60c11,0,20,9,20,20C102.7,37.1,93.8,46.1,82.7,46.1z"/>
<path class="over" d="M102.7,26.1c0,20.4-11.5,26.1-50,26.1c-37.2,0-50-6.9-50-26.1C2.7,6.9,14,0,52.7,0S102.7,7.6,102.7,26.1z"/>
<path class="down" d="M82.8,43.2c-20-2-40.2-1.9-60.1,0.2c-11,1.5-19.9-5.8-19.9-17.3c0-11.5,8.9-18.8,19.9-17.3c20,2.2,40.2,2.2,60.1,0.2 c11-1.4,19.9,5.8,19.9,17.1C102.7,37.4,93.8,44.6,82.8,43.2z"/>
</svg>


<button><span>I'm a button!</span></button>  
            
          
!
            
              body{
  padding: 6em;
  text-align: center;
}
button{
  padding: 2em;
  font-size: 20px;
  border: 0;
  font-weight: bold;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  position: relative;
  background: none;
  color: white;
  outline: 0;
  cursor: pointer;
  transition: all .1s ease-in;
  
}
button>span{
  position: relative;
}
button>svg{
  position: absolute;
  left:0;
  right:0;
  top:0;
  bottom:0;
  width: 100%;
  height: 100%;
  display: block;
  fill: url(#btn-grad);
}
button:active,
button:hover:active{
  transform: scaleX(1.1);
}
button:hover{
  transform: scaleY(1.05);
}
            
          
!
            
              function MorphButton( btn, svg ){

    if( !(this instanceof MorphButton) ){
      new MorphButton( btn, svg );
      return;
    }

    function getObjects(selector){
      var objs = [];
      if( typeof selector == 'string' ){
        objs = document.querySelectorAll(selector);
      } else {
        if( 'forEach' in selector ){
          objs = selector;
        } else {
          objs = [selector];
        }
      }
      return objs;
    }

    var btnObjects = getObjects(btn),
        svgObject = getObjects(svg)[0];


    var btnStates = {
      default: svgObject.querySelector('path:nth-child(1)').getAttribute('d'),
      over: svgObject.querySelector('path:nth-child(2)').getAttribute('d'),
      down: svgObject.querySelector('path:nth-child(3)').getAttribute('d')
    };

    function initBtn(b){

      //insert an svg/path
      var s = document.createElementNS("http://www.w3.org/2000/svg", "svg");
      s.setAttribute('preserveAspectRatio',svgObject.getAttribute('preserveAspectRatio'));
      s.setAttribute('viewBox', svgObject.getAttribute('viewBox'));
      var path = document.createElementNS(s.namespaceURI,'path');
      s.appendChild(path);
      path.setAttribute('d',btnStates.default);
      s.setAttribute('fill','black');

      b.insertBefore(s,b.firstChild);

      //rig it to animations
      b.addEventListener('mouseenter',function(){
        TweenLite.to( path, .3, { morphSVG: btnStates.over, ease: Bounce.easeOut });
      });
      b.addEventListener('mouseleave',function(){
       TweenLite.to( path, .3, { morphSVG: btnStates.default, ease: Bounce.easeOut });
      });
      b.addEventListener('mousedown',function(){
        TweenLite.to( path, .3, { morphSVG: btnStates.down, ease: Bounce.easeOut });
      });
      b.addEventListener('mouseup',function(){
        TweenLite.to( path, .3, { morphSVG: btnStates.over, ease: Bounce.easeOut });
      });

    }

    //inject the svg
    btnObjects.forEach(initBtn);
};

MorphButton('button','#morph-button-states');

            
          
!
999px
Loading ..................

Console