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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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.

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">RUN</button>
<button id="reset">RESET</button>

<!-- <svg width="800" height="800">
  <defs>
    <path stroke-width="30" class="path" d="M100,80c150,150,250,-150,400,0" />
</defs>
</svg> -->
  
<svg xmlns="http://www.w3.org/2000/svg" x="0" y="0" width="753.93" height="148.68" viewBox="0 0 753.93 148.68">
  <title>simple_banner_straight_short</title>
    <g>
      <polyline 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 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 x1="101.89" y1="5" x2="651.61" y2="5" style="fill: none;stroke: #000;stroke-linecap: round;stroke-miterlimit: 10;stroke-width: 10px"/>
      <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"/>
    </g>
</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: #000

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

              
                console.clear();
var log = console.log.bind(console);

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");

// wrap all the converted paths in a defs container
var defs = document.createElementNS (xmlns, "defs");
root.appendChild(defs);
$(root).find('path').detach().appendTo(defs);
var initialContents = root.innerHTML;

var space = 1;
var total = colors.length;

var ratio = 1 / total;
// var loops = 2;
var loops = 1;
var time = 2;

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);
    console.log(newMask);
    cnt++;
  }
}


function inAndOut() {

  for ( let path of selectorsArr ) {

    var mask = document.getElementById(path.getAttribute('mask'));
    
    // var length = path.getTotalLength();    
    var length = DrawSVGPlugin.getLength(path);
    var max = "100%";
    
    var offset = length / total;
    var pathID = path.id;
    
    TweenLite.set(path, { strokeDasharray: `${offset + space},${length - offset - space}` });
    
    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 });
      TweenLite.set(maskPath, { drawSVG: 0, strokeLinecap: "initial" });
      
      tl.to(maskPath, time, { drawSVG: max }, 0)
        .to(pathClone, time, { strokeDashoffset: `-=${length}`, repeat: loops }, 0)
        .set(maskPath, { drawSVG: `${hideStep}% ${max}` }, "hide")
        .to(maskPath, hideTime, { drawSVG: `${max} ${max}` }, "hide");

      return tl;

    }, new TimelineMax());
  }
}

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

$('button#reset').on("click", function(){
  root.innerHTML = initialContents;
});

              
            
!
999px

Console