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

              
                <div id="stage-container">
  <h2>Rotate, resize and drag</h2>
  <p>Top-left handle rotates and bottom-right handle resizes. Drag from anywhere in the middle of the SVG. This SVG has a transparent circle to give you something to grab with the mouse. To use this for sparse SVGs that can easily have 'empty' areas, you'll want to dynamically add a transparent shape of some kind.</p>
  <svg xmlns="http://www.w3.org/2000/svg" id="stage" width="800" height="600">
    <!-- wrap each svg with its own group tag and place the id on the group -->
    <g class="svg-wrapper" id="gp-0">
      <svg id="svg-0" class="svg inline" viewBox="0 0 170 170" height="170" width="170">
        <g id="Background"/>
        <g id="Circle">
          <path fill="rgba(255,255,255,0)" d="M85 170c-46.87 0-85-38.13-85-85S38.13 0 85 0s85 38.13 85 85S131.87 170 85 170z"/>
        </g>
        <g id="TEXT"/>
        <g id="Icons">
          <path fill="none" stroke="#282D33" stroke-width="4" stroke-dasharray="4.03" d="M87.65 131.3c-26.93 0-48.74-21.82-48.74-48.73 0-26.9 21.82-48.69 48.75-48.69 26.92 0 48.69 21.8 48.69 48.69C136.34 109.48 114.56 131.3 87.65 131.3z"/>
          <path fill="none" stroke="#282D33" stroke-width="4" d="M79.06 74.55c0 4.35-3.52 7.88-7.88 7.88l0 0c-4.35 0-7.87-3.53-7.87-7.88V63.81c0-4.35 3.52-7.88 7.88-7.88l0 0c4.36 0 7.88 3.53 7.88 7.88V74.55z"/>
          <path fill="none" stroke="#282D33" stroke-width="4" d="M111.94 101.37c0 4.35-3.52 7.88-7.88 7.88l0 0c-4.35 0-7.88-3.53-7.88-7.88V90.62c0-4.35 3.53-7.88 7.88-7.88l0 0c4.36 0 7.88 3.53 7.88 7.88V101.37z"/>
          <polyline fill="none" stroke="#282D33" stroke-width="4" points="114.6 71.16 114.6 55.6 99.04 55.6 "/>
          <line fill="none" stroke="#282D33" stroke-width="4" x1="114.38" y1="55.83" x2="60.63" y2="109.58"/>
        </g>
      </svg>
      <rect class="ga-handle" id="resizeHandler" fill="#7CFC00" width="10px" height="10px"/>
      <rect class="ga-handle" id="rotateHandler" fill="#7CFC00" width="10px" height="10px"/>
    </g>
  </svg>
</div>
              
            
!

CSS

              
                body,html { height: 100%; width: 100%;}
body { overflow:hidden; background-color: #333;}
#stage-container { 
  width: 800px; 
  height: 600px; 
  background-color: #fff;
  padding: 10px;
}
#stage { background: transparent; width: 800px; height: 600px; overflow: hidden; }

              
            
!

JS

              
                function setTransforms() {
  $("g.svg-wrapper").each(function() {

    var drag = $(this),
        nestedSVG = $("svg.svg.inline"),
        handle = $('#stage').find("#resizeHandler"),
        rHandle = $('#stage').find("#rotateHandler");
    
    var nB = nestedSVG[0].getBBox(),
        hB = handle[0].getBBox();
    
    const WD = nB.width;
    const HT = nB.height;
    const rt = WD/HT;
    
    var rotating = null;
    console.log(nestedSVG); // makes it easier to select the svg in real inspector
    TweenLite.set(rHandle, { x: nB.x, y: nB.y  });
    TweenLite.set(handle, { x: nB.x+nB.width-10, y: nB.height+nB.y-10 });
    TweenLite.set(drag,{transformOrigin:"center center"});
    Draggable.create(drag, { throwProps:true , bounds: "#stage-container" });

    Draggable.create(handle, {
      cursor: 'se-resize',
      bounds:{minX:70,minY:70,maxX:Number.MAX_VALUE,maxY:Number.MAX_VALUE},
      onPress: function(e) { e.stopPropagation(); },
      onDrag: function() {
        var wd = this.x+hB.width;
        var scaleAmt = wd/WD;
        var newWd = Math.round(WD*scaleAmt);
        var newHt = Math.round(HT*scaleAmt);
        TweenLite.set(drag, { width: wd, height: this.y+hB.height }); 
        TweenLite.set(nestedSVG, {scale: scaleAmt, attr:{height: newHt, width: newWd}});
        TweenLite.set('.ga-handle', {scale: 1.0});
        var newnB = nestedSVG[0].getBBox();
        TweenLite.set(handle, { attr:{x: newWd-10, y: newHt-10}});
        handle.removeAttr('style');
      }
    });

    rHandle.on("mousedown" , function () {
      Draggable.get(drag).kill();
      TweenLite.set(drag,{transformOrigin:"center center"});
      rotating = Draggable.create(drag, { throwProps:true , type:"rotation" });
    })

    $("body").on("mouseup" , function () {
      if (rotating) {
        rotating[0].kill();
        rotating = null;
        Draggable.create(drag, { throwProps:true , bounds: "#stage-container"});
      }
    })
  });
}

setTransforms();

              
            
!
999px

Console