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

              
                <div class="controls">
  <button class="button" data-zoom="0.5">Zoom 50%</button>
  <button class="button" data-zoom="0.75">Zoom 75%</button>
  <button class="button" data-zoom="1.0">Zoom 100%</button>
  <button class="button" data-zoom="1.25">Zoom 125%</button>
  <button class="button" data-zoom="1.5">Zoom 150%</button>
  <button class="button" data-zoom="2.0">Zoom 200%</button>
</div>
<div class="container"></div>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

body {
  overflow: scroll;
}

.controls {
  padding: 15px;
  background: rgba(0,0,0,0.5);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1;
}

.container {
  background: #ccc;
  width: 1000px;
  height: 1000px;
  transform-origin: 0px 0px;
}

.box {
  position: absolute;
  padding: 10px;
  color: white;
  font-weight: bold;
}

#box1 {
  background: red;
}

#box2 {
  background: blue;
}

#box3 {
  background: green;
}

#box4 {
  background: orange;
}
              
            
!

JS

              
                console.clear();

var container = $(".container");

var boxData = [
  { x: 100, y: 200, width: 100, height: 200, rotation: 0, id: "box1" },
  { x: 300, y: 400, width: 125, height: 200, rotation: 90, id: "box2" },
  { x: 400, y: 100, width: 150, height: 275, rotation: 0, id: "box3" },
  { x: 600, y: 400, width: 200, height: 250, rotation: 0, id: "box4" },
]

var draggables = [];

for (var i = 0; i < boxData.length; i++) {
  var draggable = initDraggable(boxData[i]);
  draggables.push(draggable);
}

$(".button").click(function() {  
  TweenLite.to(container, 0.2, {
    scale: $(this).data("zoom")
  });
});

// Showing how you can loop through and grab positions of draggables
draggables.forEach(function(draggable, index) {

  var target = draggable.target;
  var transform = target._gsTransform;
  console.log("\nBox" + (index + 1));
  console.log("Rotation", transform.rotation);
  console.log("X", transform.x);
  console.log("Y", transform.y);
});

function initDraggable(data) {
  
  var box = $('<div class="box" id="' + data.id + '">').html(data.id).appendTo(container);
  
  TweenLite.set(box, {
    width: data.width,
    height: data.height,
    x: data.x,
    y: data.y,
    rotation: data.rotation
  });
  
  var draggable = new Draggable(box, {
    onClick: function() {
      
      var rotation = this.target._gsTransform.rotation;
      var newRotation = (rotation === 0) ? 90 : 0;
      
      TweenLite.to(this.target, 0.3, { rotation: newRotation });
    }
  });
  
  return draggable;
}
              
            
!
999px

Console