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.

            
              <h1>SVG Animated Buttons</h1>
<h2>Animate with SVG baby!</h2>
<p>Doing the SVG line animation with variable size buttons could be hard, but with a little JS, you can use any size button and get the same effect without any math on your part. Because thinking is for losers.</p>
<div class="container">
  <p>
<button type="button" class="btn btn-svg">
  <svg class="btn_svg" version="1.1" viewBox="0 0 30 20" preserveAspectRatio="none">
    <rect class="btn_svg_shape" width="30" height="20"/>
  </svg>
  <span>This is a button</span>
</button>
  </p>
  
    <p>
<button type="button" class="btn btn-svg btn-big">
  <svg class="btn_svg" version="1.1" viewBox="0 0 30 20" preserveAspectRatio="none">
    <rect class="btn_svg_shape" width="30" height="20"/>
  </svg>
  <span>This is a button</span>
</button>
  </p>
  
    <p>
<button type="button" class="btn btn-svg btn-small">
  <svg class="btn_svg" version="1.1" viewBox="0 0 30 20" preserveAspectRatio="none">
    <rect class="btn_svg_shape" width="30" height="20"/>
  </svg>
  <span>This is a button</span>
</button>
  </p>
</div>
            
          
!
            
              .btn {
  position: relative;
  overflow: hidden;
  background: none;
  padding: 1em;
  background-color: transparent;
  transition: background-color 250ms ease-in;
  font-size: 1.5rem;
  color: orange;
  .transition(background-color, color;);
  border: none;
  
  &.btn-small {
    font-size: 1rem;
  }
  &.btn-big {
    font-size: 2rem;
  }
  
  &:before {
    content: "";
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    
    border: 1px solid orange;
    opacity: 1;
    .transition(opacity;);
  }
  
  > span {
    position: relative;
  }
  
  .btn_svg {
    position: absolute;
    top: 0;
    left: 0;
    
    width: 100%;
    height: 100%;
  }
  .btn_svg_shape {
    stroke: orange;
    stroke-width: 2px;
    stroke-linecap: round;
    fill: transparent;
    
  }
  
  &:hover {
    transition-delay: 250ms;
    background-color: fade(black, 40%);
    color: white;
    
    &:before {
      opacity: 0;
    }
    
    .btn_svg_shape {
      .transition(stroke-dasharray, stroke-dashoffset; 500ms;);
      stroke-dashoffset: 0 !important;
      animation: 500ms pencil ease-in forwards;
    }
  }
}

/* Stroke animation. Use ems to scale :) */
@keyframes pencil{
  0% {
    stroke-width: 0.5em;
  }
  75% {
    stroke-width: 0.25em;
  }
  100%{
    stroke-width: 0.1em;
  }
}

/* Transition mixin, cause lazy */
.transition(@properties, @duration: 250ms, @easing: ease-in-out, @delay: 0){
    transition-property: @properties;
    transition-duration: @duration;
    transition-timing-function: @easing;
    transition-delay: @delay;
}

/* W00t border-box */
* {
  box-sizing: border-box;
  &:after,
  &:before {
    box-sizing: border-box;
  }
}

/* Make things perty */
html {  height: 100%;}
body { font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif; background: url(http://www.jmchristensendesign.com/wp-content/themes/jmcdsn/images/intro_default-background.jpg); color: #fff; height: 100%; padding-top: 2em; text-align: center;}
h1, h2{ margin: 0; text-transform: uppercase;text-shadow: 0 0 0.5em black;}
h2 { font-weight: 300}
input { border: 1px solid #666; background: #333; color: #fff; padding: 0.5em; box-shadow: none; outline: none !important; margin: 1em  auto; text-align: center;}
a { color: orange; text-decoration: none; transition: color 250ms ease-in-out;}
a:hover { color: yellow;}
.container { display:block; margin: 2em 0;}
p {max-width: 40em; margin: 1em auto;}
            
          
!
            
              jQuery(document).ready(function(){
  
  $('.btn-svg').each(function(){
    var 
      $this = $(this),
      width = $this.outerWidth(),
      height = $this.outerHeight(),
      $svg = $this.find('svg'),
      $rect = $svg.find('rect'),
      totalPerimeter = width*2+height*2;
        
    $svg[0].setAttribute('viewBox', '0 0 '+width+' '+height);
    $rect.attr('width', width);
    $rect.attr('height', height);
    $rect.css({ 
      strokeDashoffset: totalPerimeter,
      strokeDasharray: totalPerimeter
    });
  });
  
});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console