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 class="draw">Draw</button><button class="reset">Reset</button>
<div id="stage" width="800" height="600" style="width: 800px; height: 600px;">
  <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="800" height="600" x="0" y="0" id="stage-master" style="background: rgba(0, 0, 0, 0);">
    
<!--     <g id="gp-1" class="svg-wrapper" ref="3" x="0" y="0" height="308" width="308" data-svg-origin="220.5 220.5" style="transform-origin: 0px 0px 0px; transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); z-index: 1006;">
      <g id="flipper-1" class="ga-flipper">
        <svg xmlns="http://www.w3.org/2000/svg" id="svg-1" viewBox="0 0 308 308" class="svg inline" role="img" ref="3" height="443" width="443" x="0" y="0" data-svg-origin="154 154" style="transform-origin: 0px 0px 0px; transform: matrix(1.42903, 0, 0, 1.42903, -66.071, -66.071);">
          <title>Rectangle</title>
          <rect x="4" y="4" fill="white" stroke="black" stroke-width="4" stroke-miterlimit="8" width="300" height="300"></rect>
          <rect class="ga-selector" x="0" y="0" width="100%" height="100%" fill="rgba(0,0,0,0)" vector-effect="non-scaling-stroke" stroke="#8b9dc3" stroke-width="3" stroke-miterlimit="6" stroke-dasharray="1 5" style="opacity: 1; cursor: move; touch-action: none; -webkit-user-select: none;"></rect>
        </svg>
      </g>
    </g> -->

<!--     <g id="gp-1" class="svg-wrapper" ref="1" x="0" y="0" height="256" width="256" data-svg-origin="207.5 207.5" style="transform-origin: 0px 0px 0px; transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 191.5, 91.5, 0, 1); z-index: 1003;">
      <svg xmlns="http://www.w3.org/2000/svg" id="svg-1" viewBox="0 0 256 256" class="svg inline" role="img" ref="1" height="417" width="417" x="0" y="0" data-svg-origin="128 128" style="transform-origin: 0px 0px 0px; transform: matrix(1.6289, 0, 0, 1.6289, -80.5, -80.5);">
        <path fill="none" stroke="#000000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d="  M119.6,188.9H22.4c-6.5,0-13.3-4.9-13.3-11.4V81.3c0-6.5,6.8-12.4,13.3-12.4h3.5c6.5,0,11.7-5.1,11.7-11.6l1.2-12.4  c0-6.5,4.1-12,10.6-12h44c6.5,0,14.3,4.5,17.4,10.1l8.7,16c3.1,5.7,10.9,9.8,17.4,9.8h90.9c6.5,0,10.4,5.9,10.4,12.4v15.2"></path>
        <path fill="none" stroke="#000000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d="  M246.9,167.4c0-27.7-23.6-55.3-55.1-55.3c-35.5,0-57.4,27.6-57.4,55.3s19,55.7,55.2,55.7C225.3,222.9,246.9,195.1,246.9,167.4z"></path>
        <path fill="none" stroke="#000000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d="  M176.7,138c-2.7,2.9-4,6.5-4,10.8 M203.1,137.4c-2.5-2.3-5.7-3.9-10-4.2c-1.4-0.1-4.3-0.1-5.7,0c-4.8,0.2-8,2.1-10.7,5 M207.9,146.5  c-0.7-3.9-2.3-7.1-4.8-9.4 M172.7,148.9c0,4.2,1.1,7.8,3.5,10.8s9.2,5.9,14.6,7.6 M190.1,122.4v90 M207.9,185.6  c0-4.2-1.1-7.8-3.5-10.8s-8-5.9-13.2-7.3 M203.9,196.3c2.7-2.9,4-6.5,4-10.8 M177.5,197.1c2.5,2.3,5.7,3.8,10,4.3c0,0,10,2,16.4-5   M172.7,187.8c0.7,3.9,2.3,7.1,4.8,9.4"></path>
      </svg>
    </g> -->
    
    <g id="gp-1" class="svg-wrapper" ref="1" x="0" y="0" height="256" width="256" data-svg-origin="204.5 204.5" style="transform-origin: 0px 0px 0px; transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1); z-index: 1004;">
    <g id="flipper-1" class="ga-flipper">
        <svg xmlns="http://www.w3.org/2000/svg" id="svg-1" viewBox="0 0 256 256" class="svg inline" role="img" ref="1" height="411" width="411" x="0" y="0" data-svg-origin="128 128" style="transform-origin: 0px 0px 0px; transform: matrix(1.60546, 0, 0, 1.60546, -77.5, -77.5);">
            <g id="Tables">
            </g>
            <polyline fill="none" stroke="#000000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points="  198.5,198.7 198.5,243.2 58.5,243.2 58.5,199.7 "></polyline>
            <rect x="100.5" y="113.2" fill="none" stroke="#000000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" width="55" height="130"></rect>
            <polygon fill="none" stroke="#000000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points="  217.5,159.2 211.5,159.2 211.5,188.1 198.6,199.6 184.5,188.1 184.5,159.2 177.5,159.2 177.5,130.2 217.5,130.2 "></polygon>
            <polygon fill="none" stroke="#000000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points="  77.5,159.2 71.5,159.2 71.5,188.1 58.6,199.6 44.5,188.1 44.5,159.2 37.5,159.2 37.5,130.2 77.5,130.2 "></polygon>
            <path fill="none" stroke="#000000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d="  M121.5,169.2V145c0-3.6,3.4-6.4,7-6.4l0,0c3.6,0,7,2.9,7,6.4v24.2H121.5z"></path>
            <path fill="none" stroke="#000000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d="  M57.7,91c0,0,7.6,16.3,10.6,21.3c7.9,13.2,16.9,17.9,16.9,17.9H57.7H30.2c0,0,7.8-3.5,16.9-17.9C50.2,107.3,57.7,91,57.7,91z"></path>
            <path fill="none" stroke="#000000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d="  M128.3,58.5c0,0,10.6,22.8,14.8,29.8c11.1,18.4,23.6,24.8,23.6,24.8h-38.4H89.9c0,0,10.9-4.7,23.6-24.8  C117.9,81.4,128.3,58.5,128.3,58.5z"></path>
            <path fill="none" stroke="#000000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d="  M198.3,91c0,0,7.6,16.3,10.6,21.3c7.9,13.2,16.9,17.9,16.9,17.9h-27.5h-27.5c0,0,7.8-3.5,16.9-17.9C190.9,107.3,198.3,91,198.3,91z"></path>
            <line fill="none" stroke="#000000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="44" y1="159.2" x2="72" y2="159.2"></line>
            <line fill="none" stroke="#000000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="184" y1="159.2" x2="211" y2="159.2"></line>
            <path fill="none" stroke="#000000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d="  M117.5,241.7v-23.5c0-6.1,5.1-11,11.2-11h0.3c6.1,0,11.5,4.8,11.5,11v23.5"></path>
            <path fill="none" stroke="#000000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d="  M50.5,152.2V145c0-3.6,3.4-6.4,7-6.4l0,0c3.6,0,7,2.9,7,6.4v7.2H50.5z M191.5,152.2V145c0-3.6,3.4-6.4,7-6.4l0,0c3.6,0,7,2.9,7,6.4  v7.2H191.5z M128.5,58.7v-5 M133.1,46.7c0,2.4-1.9,4.3-4.3,4.3s-4.3-1.9-4.3-4.3c0-2.4,1.9-4.3,4.3-4.3  C131.2,42.4,133.1,44.3,133.1,46.7z"></path>
            <path fill="none" stroke="#000000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d="  M115,88.2h26 M72,167.2h12h9h6 M156,167.2h7h8h12 M57.5,90.7v-17 M76.5,70.8l-19,9.2V61.6L76.5,70.8z M198.5,90.7v-17 M217.5,70.8  l-19,9.2V61.6L217.5,70.8z M128.5,39.7v-12 M151.3,16.1l-22.8,12.4V8.8L151.3,16.1z M129.5,207.7v34"></path>
        </svg>
    </g>
</g>


    <g id="hand" class="svg-wrapper" ref="2" x="0" y="0" height="256" width="256" data-svg-origin="55.5 55.5" style="transform-origin: 0px 0px 0px; transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1); z-index: 1006;">
    <g data-svg-origin="56.5 56.5" style="transform-origin: 0px 0px 0px; transform: matrix(1, 0, 0, -1, 0, 113);">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" class="svg inline scale-it" role="img" ref="2" height="113" width="113" x="0" y="0" data-svg-origin="128 128" style="transform-origin: 0px 0px 0px; transform: matrix(0.4414, 0, 0, 0.4414, 71.5, 71.5);">
            <g id="Tables">
            </g>
            <g>
                <polygon fill="#383234" points="12.2,248.1 8.1,244 23.2,196.6 59.3,232.7  "></polygon>
                <polygon fill="#110F10" points="12.2,248.1 8.1,244 49,222.4 59.3,232.7  "></polygon>
                <polygon fill="#F9A665" points="59.3,232.7 23.2,196.6 32.6,159.3 96.6,223.3  "></polygon>
                <polygon fill="#BF7C4F" points="58.8,234.3 49,222.4 86.3,213 96.6,223.3  "></polygon>
                <polygon fill="#CA65A7" stroke="#E57AB0" stroke-miterlimit="10" points="222.7,94.9 160.2,32.4 183.9,7.9 247.9,71.9  "></polygon>
                <polygon fill="#9E5186" points="222.7,94.9 213.7,83.9 236.8,60.8 247.9,71.9  "></polygon>
                <polygon fill="#FEC345" points="95.5,222.2 32.6,159.3 160.2,32.4 222.7,94.9  "></polygon>
                <polygon fill="#D18828" points="96.6,223.3 86.8,211.3 212.4,84.6 222.7,94.9  "></polygon>
                <g>
                    <polygon fill="none" stroke="#000000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points="    183.9,7.9 247.9,71.9 96.6,223.3 12.2,248.1 8.1,244 32.6,159.3   "></polygon>
                    <line fill="none" stroke="#000000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="33" y1="159.7" x2="95.5" y2="222.2"></line>
                    <line fill="none" stroke="#000000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="23.2" y1="196.6" x2="59.3" y2="232.7"></line>
                    <line fill="none" stroke="#000000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="222.7" y1="94.9" x2="160.2" y2="32.4"></line>
                    <path fill="none" stroke="#000000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d="    M59.3,132.6c-1.6,3.8,0.9,9.7,4.5,13.3c7.7,7.7,18.2,1.3,23.8,6.9c7,7-1.8,18.1,6.3,26.2c7.7,7.7,18.2,1.3,23.8,6.9    c3.6,3.6,4.8,8.6,3.2,12.4"></path>
                    <line fill="none" stroke="#000000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="164.7" y1="132.5" x2="203.1" y2="94.1"></line>
                    <line fill="none" stroke="#000000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="145.2" y1="152.1" x2="155.7" y2="141.6"></line>
                    <line fill="none" stroke="#000000" stroke-width="5" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="130.1" y1="167.2" x2="135.4" y2="161.9"></line>
                </g>
            </g>
        </svg>
    </g>
</g>



  </svg>
</div>
              
            
!

CSS

              
                #stage-master
  width: 800px
  height: 600px

              
            
!

JS

              
                var svgID = '#svg-1',
    hand = '#hand',
    pathArr,
    multiplier = 0.25;

// look for compound paths in the original SVG
var paths = document.querySelectorAll(`${svgID} path`);

var newPaths = breakApartPaths(paths,$(svgID)[0]);
for( path of paths ) {
  $(svgID)[0].removeChild(path);
}
for( path of newPaths ) {
  $(svgID)[0].appendChild(path);
}

MorphSVGPlugin.convertToPath(`${svgID} circle, ${svgID} rect, ${svgID} ellipse, ${svgID} line, ${svgID} polygon, ${svgID} polyline`);
pathArr = document.querySelectorAll(`${svgID} path`);

TweenMax.set(pathArr,{drawSVG: "0"});
TweenMax.to('#gp-1', 0.5, {x: 200, y: 25});

TweenLite.defaultEase = Linear.easeNone;

function reset() {
  TweenMax.set(pathArr,{drawSVG: "0"});
}

function drawIt() {
  
  var gpWD = parseInt($('#gp-1').attr('width'));
  var gpHT = parseInt($('#gp-1').attr('height'));
  var svgWD = parseInt($('#svg-1').attr('width'));
  var svgHT = parseInt($('#svg-1').attr('height'));
  var scaleX = svgWD/gpWD;
  var scaleY = svgHT/gpHT;
  
  var tl = new TimelineMax();
  
  for ( let path of pathArr ) {

    var TL = new TimelineMax(),
        time = (parseInt(path.getTotalLength())/100)*multiplier,
        data = path.getAttribute('d'),
        bzPath = MorphSVGPlugin.pathDataToBezier(data);
    if( scaleX !== 1 || scaleY != 1 ) {
      bzPath = scaleBezier(scaleX, scaleY, bzPath);
    }
    TL.fromTo(hand,0.2,{x: hand.x, y: hand.y, scaleX: 1.1, scaleY: 1.1},{x: bzPath[0].x, y: bzPath[0].y, scaleX: 1, scaleY: 1, ease: Power4.easeIn}, 0)
      .fromTo(path, time, {drawSVG: "0"}, {drawSVG: "100%"}, multiplier)
      .to(hand, time, {bezier:{values:bzPath, type:"cubic"}}, multiplier);
    tl.add(TL);
  }
  // var total = tl.totalDuration();
  // tl.to(hand,0.5,{x: 300, y: 200, ease: Power4.easeIn},total);
  return tl;
}

function scaleBezier(scaleX,scaleY,bzPath) {
  var newPath = [];
  for ( let coords of bzPath ) {
    var X = coords.x*scaleX+$('#gp-1')[0]._gsTransform.x;
    var Y = coords.y*scaleY+$('#gp-1')[0]._gsTransform.y;
    newPath.push({x: X, y: Y});
  }
  return newPath;
}

function breakApartPaths(paths, svg) {
  var sepPaths = [];
  for ( let path of paths ) {
    var pdata = path.getAttribute('d');
    pdata = pdata.trim();
    var subArr = pdata.split('M');
    for ( let M of subArr ) {
      if(M != "") {
        var newPath = document.createElementNS("http://www.w3.org/2000/svg", 'path');
        for ( var a = 0; a < path.attributes.length; a++ ) {
          var N = path.attributes[a].name;
          var V = path.attributes[a].value;
          if(N != 'd') {
            newPath.setAttributeNS('',N,V);
          }
        }
        newPath.setAttributeNS('','d',`M${M}`);
        sepPaths.push(newPath);
      }
    }
  }
  return sepPaths;
}

$('button.draw').on("click", function(){
  reset();
  var TL = drawIt();
  TL.play();
})

$('button.reset').on("click", function(){
  reset();
});
              
            
!
999px

Console