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

              
                <button id="run">PROCESS</button>
<button id="reset">RESET</button>
<button id="play">REPLAY</button>

<!-- Straight lines won't draw in this version -->
<!-- <svg id="main" xmlns="http://www.w3.org/2000/svg" width="753.93" height="148.68" viewBox="0 0 753.93 148.68">
  <line id="bottom-line" x1="651.61" y1="123.7" x2="101.89" y2="123.7" style="fill: none;stroke: #000;stroke-linecap: round;stroke-miterlimit: 10;stroke-width: 10px"/>
  <polyline id="left-bracket" points="120.33 24.98 10.08 24.98 55.02 84.52 10.08 143.68 224.05 143.68" style="fill: none;stroke: #000;stroke-linecap: round;stroke-miterlimit: 10;stroke-width: 10px"/>
  <polyline id="right-bracket" points="633.17 24.98 743.8 24.98 698.48 84.52 743.8 143.68 529.45 143.68" style="fill: none;stroke: #000;stroke-linecap: round;stroke-miterlimit: 10;stroke-width: 10px"/>
  <line id="top-line" x1="101.89" y1="5" x2="651.61" y2="5" style="fill: none;stroke: #000;stroke-linecap: round;stroke-miterlimit: 10;stroke-width: 10px"/>
</svg> -->

<!-- Straight lines draw in this version of the above SVG -->
<svg xmlns="http://www.w3.org/2000/svg" width="753.93" height="148.68" viewBox="0 0 753.93 148.68">
  <path fill="none" stroke="#000" stroke-linecap="round" stroke-miterlimit="10" stroke-width="10" d="M651.61 123.7H101.89M120.33 24.98H10.08l44.94 59.54-44.94 59.16h213.97M633.17 24.98H743.8l-45.32 59.54 45.32 59.16H529.45M101.89 5h549.72"/>
</svg>

<!-- Straight lines won't draw -->
<!-- <svg xmlns="http://www.w3.org/2000/svg" width="256" height="44" viewBox="0 0 256 44">
  <title>straight-lines</title>
  <line x1="4" y1="40" x2="252" y2="40" fill="none" stroke="#000" stroke-linecap="round" stroke-miterlimit="10" stroke-width="8"/>
  <line x1="4" y1="4" x2="252" y2="4" fill="none" stroke="#000" stroke-linecap="round" stroke-miterlimit="10" stroke-width="8"/>
</svg> -->

<!-- this version of the above works! -->
<!-- <svg xmlns="http://www.w3.org/2000/svg" width="256" height="44" viewBox="0 0 256 44">
  <title>
    straight-lines
  </title>
  <path fill="none" stroke="#000" stroke-linecap="round" stroke-miterlimit="10" stroke-width="8" d="M4 40h248M4 4h248"/>
</svg> -->





<!-- Straight lines won't draw -->
<!-- <svg id="main" xmlns="http://www.w3.org/2000/svg" width="301.16" height="76.6" viewBox="0 0 301.16 76.6">
  <title>mid-circle-long</title>
  <circle id="middle" cx="150.52" cy="38.3" r="36.8" style="fill: none;stroke: #000;stroke-linecap: round;stroke-miterlimit: 10;stroke-width: 3px"/>
  <g id="left">
    <polyline id="bracket" points="111.12 20.8 3.02 20.8 14.72 36.2 3.02 51.7 31.12 51.7" style="fill: none;stroke: #000;stroke-linecap: round;stroke-miterlimit: 10;stroke-width: 3px"/>
    <line id="top-line" x1="109.12" y1="24.8" x2="21.02" y2="24.8" style="fill: none;stroke: #000;stroke-linecap: round;stroke-miterlimit: 10;stroke-width: 3px"/>
    <line id="bottom-line" x1="112.12" y1="55.8" x2="24.02" y2="55.8" style="fill: none;stroke: #000;stroke-linecap: round;stroke-miterlimit: 10;stroke-width: 3px"/>
  </g>
  <g id="right">
    <polyline id="bracket-2" data-name="bracket" points="190.02 20.8 298.12 20.8 286.32 36.2 298.12 51.7 270.02 51.7" style="fill: none;stroke: #000;stroke-linecap: round;stroke-miterlimit: 10;stroke-width: 3px"/>
    <line id="top-line-2" data-name="top-line" x1="192.02" y1="24.8" x2="280.12" y2="24.8" style="fill: none;stroke: #000;stroke-linecap: round;stroke-miterlimit: 10;stroke-width: 3px"/>
    <line id="bottom-line-2" data-name="bottom-line" x1="189.02" y1="55.8" x2="277.12" y2="55.8" style="fill: none;stroke: #000;stroke-linecap: round;stroke-miterlimit: 10;stroke-width: 3px"/>
  </g>
</svg> -->

<!-- This works where the version commented out above doesn't -->
<!-- <svg xmlns="http://www.w3.org/2000/svg" width="301.16" height="76.6" viewBox="0 0 301.16 76.6">
  <title>
    box
  </title>
  <circle cx="150.52" cy="38.3" r="36.8" fill="none" stroke="#000" stroke-linecap="round" stroke-miterlimit="10" stroke-width="3"/>
  <path d="M111.12 20.8H3l11.7 15.4L3 51.7h28.1m78-26.9H21m91.1 31H24M190 20.8h108.1l-11.8 15.4 11.8 15.5H270M192 24.8h88.1M189 55.8h88.1" fill="none" stroke="#000" stroke-linecap="round" stroke-miterlimit="10" stroke-width="3"/>
</svg> -->




<!-- These all work fine -->
<!-- <svg width="100%">
  <defs>
    <path stroke-width="30" fill="none" class="path" d="M100,80c150,150,250,-150,400,0" />
</defs>
</svg>
 -->

<!-- <svg xmlns="http://www.w3.org/2000/svg" width="170" height="170" viewBox="0 0 170 170">
  <title>
    alphabet
  </title>
  <path d="M85 2.5A82.51 82.51 0 0 0 22.1 138.4l-8.3 25.5 24.1-11.3A82.35 82.35 0 0 0 167.5 85M167.5 85V81.4" style="fill: none;stroke: #282d33;stroke-width: 5px"/>
  <path d="M166.8,74.2A82.46,82.46,0,0,0,92.2,2.8" style="fill: none;stroke: #282d33;stroke-width: 5px;stroke-dasharray: 4.002299785614014,4.002299785614014"/>
  <path d="M88.6,2.7H85" style="fill: none;stroke: #282d33;stroke-width: 5px"/>
  <g>
    <path d="M72.8,83H88.1a12.25,12.25,0,0,1,12.2,12.2h0a12.25,12.25,0,0,1-12.2,12.2H71" style="fill: none;stroke: #282d33;stroke-width: 5px"/>
    <path d="M70.8 62.3h13A10.39 10.39 0 0 1 94.2 72.7h0A10.39 10.39 0 0 1 83.8 83.1h-11M73.5 58.9L73.5 111" style="fill: none;stroke: #282d33;stroke-width: 5px"/>
    <g>
      <path d="M37.6 111V73.3A11.14 11.14 0 0 1 48.7 62.2h0A11.14 11.14 0 0 1 59.8 73.3V111M60.2 82.3L38.3 82.3" style="fill: none;stroke: #282d33;stroke-width: 5px"/>
    </g>
    <path d="M132.5,98.1a11,11,0,0,1-11,11h0a11,11,0,0,1-11-11V73a11,11,0,0,1,11-11h0a11,11,0,0,1,11,11" style="fill: none;stroke: #282d33;stroke-width: 5px"/>
  </g>
</svg> -->


<!-- <svg id="Layer_1" xmlns="http://www.w3.org/2000/svg" width="170" height="170" viewBox="-314 316 170 170">
  <style>
    .st0{fill:none;stroke:#282D33;stroke-width:5;stroke-dasharray:4;} .st1{fill:none;stroke:#282D33;stroke-width:5;} .st2{fill:none;stroke:#282D33;stroke-width:5;stroke-dasharray:4.2121,4.2121;}
  </style>
  <g id="Icons">
    <path stroke-dasharray="4" class="st0" d="M-191.3 345c-11.9-7.2-25.9-11.3-40.8-11.3-43.7 0-79.1 35.4-79.1 79.1M-153 412.7c0-14.2-3.7-27.5-10.3-39"/>
    <path class="st1" d="M-289.1 403.3l2.7-16.4h87.9l9.2 16.7"/>
    <path stroke-dasharray="4.2121,4.2121" class="st2" d="M-277.4 399.2h71"/>
    <path class="st1" d="M-300.3 424.1l3.6-18.4h117.1l12.2 20.6M-183.5 370c0-6.8 5.5-12.4 12.4-12.4 6.8 0 12.4 5.5 12.4 12.4"/>
    <path class="st1" d="M-208.1 370c0-6.8 5.5-12.4 12.4-12.4 6.8 0 12.4 5.5 12.4 12.4M-233.8 359.5c0-4.1 3.4-7.5 7.5-7.5M-241.2 352c4.1 0 7.5 3.4 7.5 7.5M-207.9 425.2l-1.8 6.8H-290l-1.8-6.8h-19.7l9.8 43.2h104c25.7 0 47-18.7 51.2-43.2h-61.4z"/>
    <g>
      <path stroke-dasharray="4.2121,4.2121" class="st2" d="M-284.5 418.1h71"/>
    </g>
  </g>
</svg>
 -->

<!-- 
<svg id="Layer_1" xmlns="http://www.w3.org/2000/svg" width="170" height="170" viewBox="-314 316 170 170">
  <style>
    .st0{fill:none;stroke:#282D33;stroke-width:5;} .st1{fill:none;stroke:#282D33;stroke-width:5;stroke-dasharray:3.9777,3.9777;}
  </style>
  <g id="Icons">
    <path class="st0" d="M-311.5 401c0-1.1 0-2.2.1-3.3"/>
    <path class="st1" stroke-dasharray="3.9777,3.9777" d="M-310.9 391.3c4.8-41 39.7-72.8 81.9-72.8 43.4 0 78.9 33.5 82.2 76"/>
    <path class="st0" d="M-146.6 397.7c0 1.1.1 2.2.1 3.3M-146.5 401c0 45.6-36.9 82.5-82.5 82.5s-82.5-36.9-82.5-82.5"/>
    <g>
      <path class="st0" d="M-269 411.7h-12c0 24.3 23.3 44 52 44s52-19.7 52-44h-12"/>
      <circle class="st0" cx="-229" cy="356.6" r="11.6"/>
      <path class="st0" d="M-229 456.7v-88.5M-246.5 390.7h35"/>
    </g>
  </g>
</svg> -->
<!-- 
<svg xmlns="http://www.w3.org/2000/svg" width="168.4" height="44.3" viewBox="0 0 168.4 44.3">
  <path fill="none" stroke="#000" stroke-width="3" stroke-linecap="round" stroke-miterlimit="10" d="M73.7 8.6H5.6l11.7 15.5L5.6 39.5h98.1"/>
  <path fill="none" stroke="#000" stroke-width="3" stroke-linecap="round" stroke-miterlimit="10" d="M22.6 4.6h128.1l13.2 15.5-13.2 15.4H52.6"/>
</svg> -->


<!-- <svg xmlns="http://www.w3.org/2000/svg" width="172.57" height="162.9" viewBox="0 0 172.57 162.9">
  <title>
    hand-pencil
  </title>
  <path d="M38.9 46.3V53l23.3 27.1a24.07 24.07 0 0 0 9.8 5.4v5.2" fill="none" stroke="#282d33" stroke-width="5px"/>
  <path d="M55.1 50V29.4a12.29 12.29 0 0 0-12.3-12.3h-4.1v11.5" fill="none" stroke="#282d33" stroke-width="5px"/>
  <path d="M10 29H3.9a1.55 1.55 0 0 0-1.4 1.6v12.1a1.68 1.68 0 0 0 1.4 1.8H10" fill="none" stroke="#282d33" stroke-width="5px"/>
  <path fill="none" stroke="#282d33" stroke-width="5px" d="M150.7 28.7h2.5l14.3 8.1-14.3 8.1h-2.5"/>
  <path fill="none" stroke="#282d33" stroke-width="5px" d="M120.4 46.5h30.7V27h-30.7"/>
  <path fill="none" stroke="#282d33" stroke-width="5px" d="M53.3 27H13v19.5h40.3"/>
  <path d="M38.9 49.2V53l23.3 27.1a24.07 24.07 0 0 0 9.8 5.4v5.2" fill="none" stroke="#282d33" stroke-width="5px"/>
  <path d="M112.3 90.7v-8.9a21.88 21.88 0 0 0 8.6-17.3V27l-.3-8.3a8.07 8.07 0 0 0-8.1-8.1c-4.5 0-8.1 1.6-8.1 6v-2a8.1 8.1 0 1 0-16.2 0v-4a8.1 8.1 0 0 0-16.2 0v4.5c0-3.8-3.8-7.8-8.5-7.8a8.28 8.28 0 0 0-8.3 8.3V50" fill="none" stroke="#282d33" stroke-width="5px"/>
  <path fill="none" stroke="#282d33" stroke-width="5px" d="M66.9 162.9v-66h66.5v66"/>
  <path fill="none" stroke="#282d33" stroke-width="5px" d="M66.9 162.9v-66h66.5v66"/>
  <path fill="none" stroke="#282d33" stroke-width="5px" d="M123.5 108.2v7.2"/>
</svg> -->
  
              
            
!

CSS

              
                html, body
  height: 100%

body
  overflow: hidden
  background: #fff

svg
  position: absolute
  top: 40px
  left: 0
  // background: #fff


svg 
  defs .path, .mask-path
    fill: none
    stroke: #fff

button
  position: relative
  font-size: 18px
  display: inline-block
  width: 200px
  margin: 0 auto

              
            
!

JS

              
                MorphSVGPlugin.convertToPath("circle, rect, ellipse, line, polygon, polyline");
TweenLite.defaultEase = Linear.easeNone;
var xmlns = "http://www.w3.org/2000/svg";
var colors = ["#EA4335", "#FBBC05", "#34A853", "#4285F4"];
var svgns = "http://www.w3.org/2000/svg";
var root = document.querySelector("svg");
var selectorsArr = document.querySelectorAll("path");
var initialContents = root.innerHTML;
var masterTL = new TimelineMax();
defsWrap();

var space = 1;
var total = colors.length;
var ratio = 1 / total;
var loops = 2;
var time = 2;

function defsWrap() {
  // wrap all the converted paths in a defs container
  var defs = document.createElementNS (xmlns, "defs");
  root.appendChild(defs);
  $(root).find('g').detach().appendTo(defs);
  $(root).find('path').not('g path').detach().appendTo(defs);
}

function addMasks() {
  var cnt = 0;
  
  for ( path of selectorsArr ) {
    
    var newMask = document.createElementNS (xmlns, "mask");
    newMask.setAttributeNS(null, "id", `mask-${cnt}`);
    
    var maskPath = path.cloneNode(true);
    var pathClass = (maskPath.getAttribute('class') !== null) ? maskPath.getAttribute('class') + ' mask-path' : 'mask-path';
    maskPath.setAttributeNS(null,'class',pathClass);
    maskPath.style.stroke = "#fff";
    
    path.setAttributeNS(null,'id', `path-${cnt}`);
    path.setAttributeNS(null,'mask', `mask-${cnt}`);
    
    newMask.appendChild(maskPath);
    root.appendChild(newMask);
    cnt++;
  }
}


function inAndOut() {

  for ( let path of selectorsArr ) {

    var mask = document.getElementById(path.getAttribute('mask'));
    var length = path.getTotalLength();
    console.log(path.getAttribute('stroke-width'));
    console.log(parseInt(path.style.strokeWidth));
    var strokeWidth = ( path.getAttribute('stroke-width') !== null ) ? path.getAttribute('stroke-width') : parseInt(path.style.strokeWidth);
    strokeWidth = ( isNaN(strokeWidth) ) ? parseInt($(path).css('stroke-width')) : strokeWidth;
    length += (strokeWidth*2);
    var offset = length / total;
    var pathID = path.id;
    // check for dasharray setting
    var dashArray = path.getAttribute('stroke-dasharray');
    if(dashArray === null ) {
      // check for css style
      dashArray = ( $(path).css('stroke-dasharray') !== 'none' ) ? $(path).css('stroke-dasharray') : null;
    }
    var strokeDashArraySetting = `${offset + space},${length - offset - space}`;
    if( dashArray !== null ) {
      dashArray = dashArray.split(",");
      for( var i=0; i<dashArray.length; i++ ) {
        dashArray[i] = parseFloat(dashArray[i]);
      }
      var dash = getDash(dashArray, length);
      strokeDashArraySetting = `${dash},${length}`
    }

    TweenLite.set(path, { strokeDasharray: strokeDashArraySetting });
    
    var tl = colors.reduce((tl, stroke, i) => {
    
      var hideRatio = 1 - ratio * i;
      var hideStep = 100 - 100 * hideRatio;
      var hideTime = time * hideRatio;

      var maskClone = mask.cloneNode(true);
      var pathClone = path.cloneNode(true);
      pathClone.removeAttribute('id');
      var maskPath = maskClone.querySelector(".mask-path");  
      var maskID = `url(#${maskClone.id = pathID + "-mask" + i})`;

      root.appendChild(maskClone);
      root.appendChild(pathClone);

      TweenLite.set(pathClone, { attr: { mask: maskID }, stroke, strokeDashoffset: -i * offset });
      TweenLite.set(maskPath, { drawSVG: 0 });

      tl.to(maskPath, time, { drawSVG: true }, 0)
        .to(pathClone, time, { strokeDashoffset: `-=${length}`, repeat: loops }, 0)
        .set(maskPath, { drawSVG: `${hideStep}% 100%` }, "hide")
        .to(maskPath, hideTime, { drawSVG: "100% 100%" }, "hide");
      
      masterTL.add(tl,0);
      return tl;

    }, new TimelineMax());
  }
}

function getDash(pattern, length) {

  var dash = [];
  var full = false;       
  var len  = pattern.length;
  var sum  = 0; 

  while (!full) {        
    for (var i = 0; i < len; i++) {
      var val = pattern[i];
      if (sum + val >= length) {
        full = true; break;                
      }
      sum += val;
      dash.push(val)
    }
  }    

  var last = length - sum;
  dash.length % 2 ? dash.push(0, last, length) : dash.push(last, length);
  return dash;
}

$('button#run').on("click", function(){
  console.clear();
  addMasks();
  inAndOut();
});

$('button#play').on("click", function(){
  masterTL.seek(0).play();
});

$('button#reset').on("click", function(){
  root.innerHTML = initialContents;
  MorphSVGPlugin.convertToPath("circle, rect, ellipse, line, polygon, polyline");
  root = document.querySelector("svg");
  selectorsArr = document.querySelectorAll("path");
  defsWrap();
});

              
            
!
999px

Console