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 version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" role="img" width="155" height="180" viewBox="0 0 155 180" id="svg-3" class="svg inline" ref="3" x="0" y="0">
    <title>s</title>
    <g>
        <path fill="none" stroke="rgb(0, 0, 0)" stroke-width="8" d="M77.20 72C88.24 72 104.44 75.36 104.44 83.16L104.44 87.48L121 87.48L121 58.56L104.44 58.56L104.44 64.44C98.56 60.36 85.36 56.40 74.32 56.40C58 56.40 34.96 61.56 34.96 81.84C34.96 100.44 59.68 105 68.56 106.20C87.01 108.57 97 106.92 97 114.24C97 119.40 86.80 121.20 79.72 121.20C67 121.20 49.36 118.80 49.36 108.84L49.36 104.52L32.80 104.52L32.80 134.64L49.36 134.64L49.36 131.40C55.60 134.64 65.92 136.80 77.68 136.80C107.92 136.80 121.84 127.32 121.84 112.56C121.84 84 88.48 87.24 68.68 83.64C63.76 82.80 59.56 82.08 59.56 79.32C59.56 73.16 64.20 72 77.20 72Z"></path>
    </g>
</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
  path, mask
    -webkit-mask-composite: xor

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"];
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 = 1;
var time = 1;

function addMasks() {
  var cnt = 0;
  
  for ( path of selectorsArr ) {
    
    var newMask = document.createElementNS (xmlns, "mask");
    newMask.setAttributeNS(null, "id", `mask-${cnt}`);
    newMask.setAttributeNS(null, "maskUnits", "userSpaceOnUse");
    
    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 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 });

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

      return tl;

    }, new TimelineMax());
  }
}

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

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

              
            
!
999px

Console