Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <svg width='0' height='0'>
  <defs>
    <g id='coord-syst' class='coord-syst'>
      <line x1='0' x2='650' 
            y1='0' y2='0'/>
      <line x1='0' x2='0' 
            y1='0' y2='350'/>
      
      <circle cx='0' cy='0' r='2' />
    </g>
    
    <g id='box-guides' class='box-guides'>
      <line x1='0' x2='150' y1='40' y2='40'/>
      <line x1='75' x2='75' y1='0' y2='80' />
      
      <line x1='0' y1='0' x2='150' y2='80' />
      <line x1='0' y1='80' x2='150' y2='0' />
      
      <circle cx='75' cy='40' r='2' />
    </g>
  </defs>
</svg>
<section class='code'>
  <pre><span class='token token--angled-brackets'>&lt;</span><span class='token token--tag-name'>rect</span> <span class='token token--attr-name'>transform</span><span class='token token--equal'>=</span><span class='token token--quote'>'</span><span class='inf token token--attr-val'></span><span class='token token--quote'>'</span><span class='token token--angled-brackets'>&gt;</span></pre>
</section>
<section>
  <svg>
    <g class='box box--svg box--initial'>
      <rect x='65' y='65' width='150' height='80'/>
      <use xlink:href='#coord-syst'/>
      <use x='65' y='65' xlink:href='#box-guides'/>
    </g>
    <g class='box box--svg box--transforming'>
      <rect x='65' y='65' width='150' height='80'/>
      <use xlink:href='#coord-syst'/>
      <use x='65' y='65' xlink:href='#box-guides'/>
    </g>
  </svg>
  
  <div class='ctrls paused'>
    <button id='c1'>
      <div>play</div>
      <div>pause</div>
    </button>
    <button id='c2'>reset</button>
  </div>
</section>
              
            
!

CSS

              
                @import "compass/css3";

$c: #be4c39;
$bg-c: #e18728;
$axes-c: #333;
$guides-c: #ddd;
$code-bg: #1d1f21;
$t: 6s;

body {
  margin: 0;
  
  > svg { display: none; }
}

section svg {
  overflow: hidden;
  width: 650px; height: 350px;
}

section {
  position: relative;
  width: 650px;
  margin: 0 auto;
}

.box {  
  &--svg {
    rect {
      fill: #e18728;
    }
  }
  
  &--initial {
    opacity: .5;
    
    svg & {      
      .coord-syst line {
        stroke-width: 4;
      }
    }
  }
  
  &--transforming {
    background: rgba($bg-c, .7);
    
    & rect {
      fill-opacity: .7;
      stroke: $bg-c;
      stroke-width: 2;
    }
  }
}

.coord-syst {
  line {
    stroke: $axes-c;
    stroke-width: 2;
  }
  
  circle {
    stroke: #9351a6;
    stroke-width: 4;
  }
}

.box-guides {
  line {
    //opacity: .65;
    stroke: $guides-c;
    stroke-dasharray: 9;
    stroke-width: 2;
  }
  
  circle {
    stroke: $c;
    stroke-width: 5;
  }
}

.meas {
  stroke: #222;
  
  line {
    stroke-dasharray: 7;
  }
  
  text {
    stroke: transparent;
    font: 900 italic 1em serif;
  }
}

.code {
  padding: 0 .5em;
  margin: .25em auto;
  background: $code-bg;
}

.token {
  line-height: 2;
  
  &--angled-brackets { color: #d49b00; }
  &--tag-name { color: #e18728; }
  &--attr-name { color: #be4c39; }
  &--attr-val { color: #4ca454; }
  &--equal { color: #4472b9; }
  &--quote { color: #f4e3dc; }
}

.ctrls {
  position: absolute;
  top: .5em; left: .5em;
  
  button {
    display: block;
    overflow: hidden;
    margin: .25em;
    border: solid 0;
    padding: 0;
    width: 3em; height: 2em;
    font: 1em/2 arial;
    text-align: center;
    cursor: pointer;
  }
  
  div {
    transition: .35s;
    pointer-events: none;
  }
  
  &:not(.paused) div {
    transform: translateY(-100%);
  }
  
  .cssgradients & button {
    width: 2em;
    color: transparent;
    
    &[id='c1'] {
      background: 
        linear-gradient(to right bottom, 
            $bg-c 50%, transparent 50%) 
          50% 1em, 
        linear-gradient(90deg, 
            $guides-c 35%, transparent 35%, 
            transparent 65%, $guides-c 65%) 
          50% 50%, 
        linear-gradient(to right top, 
            $bg-c 50%, transparent 50%) 
          left 50% bottom 1em 
        $axes-c;
      background-repeat: no-repeat;
      background-size: 0 0, 50% 1em;
      transition: .35s;
    }
    
    &[id='c2'] {
      box-shadow: inset 0 0 0 .5em $axes-c;
      background: $guides-c;
    }
  }
  
  .cssgradients &.paused [id='c1'] {
    background-size: 50% .5em, 0 0;
  }
}
              
            
!

JS

              
                Object.getOwnPropertyNames(Math).map(function(p) {
  window[p] = Math[p];
});

/* yeah, doing this is a bad idea... 
 * whatever... 
 * this thing checks whether a number is 
 * in the specified range, 
 * with flag dictating whether the limits are 
 * strict or not 
 * b = upper limit, defaults to 1 
 * a = lower limit, defaults to 0 
 * flag: 
 * strict limits if not specified or 0 
 * non-strict lower limit if divisible by 2 
 * non-strict upper limit if divisible by 3
 */
Number.prototype.ξ = function(b, a, flag) {
  var b = ((b - 1) || 0) + 1, 
      a = a || 0, 
      c1 = (flag && flag%2 === 0) 
  					? (this >= a) 
  					: (this > a), 
      c2 = (flag && flag%3 === 0) 
  					? (this <= b) 
  					: (this < b);
  
  return c1 && c2;
};

var sel1 = '.box--transforming', 
    sel2 = '.token--attr-val', 
    b = document.querySelector(sel1), 
    inf = document.querySelector(sel2), 
    ctrl = document.querySelector('.ctrls'), 
    d = { 'x': 140, 'y': 105 }, 
    s = { 'x': 2, 'y': 1.5 }, 
    tu = 60, 
    t = tu, r_id = null;

var ani = function() {
  var t_val, rt, x, y;
  
  if(t.ξ(tu, 0, 3)) {
    t_val = 'translate(0 0)';
    b.setAttribute('transform', t_val);
    inf.textContent = '';
  }
  
  if(t.ξ(2*tu, tu, 3)) {
    rt = t - tu;
    x = rt*d.x/tu;
    y = rt*d.y/tu;
    t_val = 'translate(' + x + ' ' + y + ')';
    b.setAttribute('transform', t_val);
    t_val = 'translate(' + round(x) + ' ' + 
      										 round(y) + ')';
    inf.textContent = t_val;
  }
  
  if(t.ξ(4*tu, 3*tu, 3)) {
    rt = t - 3*tu;
    x = (1 + rt*(s.x - 1)/tu).toFixed(2);
    y = (1 + rt*(s.y - 1)/tu).toFixed(2);
    t_val = 
      'translate(' + d.x + ' ' + d.y + ') ' + 
      'scale(' + x + ' ' + y + ')';
    b.setAttribute('transform', t_val);
    inf.textContent = t_val;
  }
  
  if(t.ξ(5*tu, 4*tu, 3)) {
    t_val = 
      'translate(' + d.x + ' ' + d.y + ') ' + 
      'scale(' + s.x + ' ' + s.y + ')';
    b.setAttribute('transform', t_val);
    inf.textContent = t_val;
  }
  
  if(t.ξ(6*tu, 5*tu, 3)) {
    rt = t - 5*tu;
    x = -rt*d.x/tu;
    y = -rt*d.y/tu;
    t_val = 
      'translate(' + d.x + ' ' + d.y + ') ' + 
      'scale(' + s.x + ' ' + s.y + ') ' + 
      'translate(' + x + ' ' + y + ')';
    b.setAttribute('transform', t_val);
    t_val = 
      'translate(' + d.x + ' ' + d.y + ') ' + 
      'scale(' + s.x + ' ' + s.y + ') ' + 
      'translate(' + round(x) + ' ' + 
      							 round(y) + ')';
    inf.textContent = t_val;
  }
  
  if(t === 7*tu) { t = 0; }
    
  t++;
  
  r_id = requestAnimationFrame(ani);
};

ctrl.addEventListener('click', function(e) {
  var target = e.target;
    
  if(target.id === 'c1') {
    if(!ctrl.classList.contains('paused')) {
      cancelAnimationFrame(r_id);
      r_id = null;
      ctrl.classList.add('paused');
    }
    else {
      ctrl.classList.remove('paused');
      ani();
    }
  }
  
  if(target.id === 'c2') {
    cancelAnimationFrame(r_id);
    r_id = null;
    t = 100;
    b.setAttribute('transform', 
                   'translate(0 0)');
    inf.textContent = '';
    ctrl.classList.add('paused');
  }
}, false);
              
            
!
999px

Console