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

              
                <form>
  <input id="count" type="textbox" value="50" />
  <div class="group">
    <input id="mod" type="checkbox" /> <label for="mod">Use modifiers</label>
  </div>
  <div class="group">
    <input id="read" type="checkbox" checked="checked" /> <label for="read">Retrieve Width</label>
  </div>
  <div class="group">
    <input id="start" type="button" value="Start" />
    <input id="reset" type="button" value="Stop" />
  </div>
</form>
<div id="container">
  <div class="box green"></div>
  <div class="box red"></div>
</div>
              
            
!

CSS

              
                body {
  background-color: #000;
  font-family: Arial;
  overflow: hidden;
  margin: 0;
}

#container {
  display: block;
  position: relative;
  height: 200px;
  width: 60vw;
  border-radius: 10px;
}

.box {
  display: block;
  position: relative;
  height: 20px;
  width: 20px;
  background-color: #71b200;
  border-radius: 10px;
  margin: 10px;
  float: left;
}

form {
  display: block;
  position: relative;
  max-width: 100%;
  background: linear-gradient(to bottom, #777 0%, #444 100%);
  padding: 20px 10px;
}

input {
  border: solid 1px black;
  appearance: none;
  font-family: Arial;
  background: linear-gradient(to bottom, #9af600 0%, #71b200 100%);
  padding: 5px;
}

label {
  color: #aaa;
}

.group {
  display: inline-block;
}

@media (max-width: 600px) {
  .group {
    display: block;
    padding: 3px 0;
  }
}

              
            
!

JS

              
                var windowWidth = window.innerWidth;
var readVals;

addBoxes();

window.addEventListener("resize", function() {
  windowWidth = window.innerWidth;
});

count.addEventListener("change", function() {
  addBoxes();
});

start.addEventListener("click", function() {
  if (mod.checked) {
    modTween();
  } else {
    normalTween();
  }
});

reset.addEventListener("click", function() {
  TweenMax.killTweensOf(".box");
  TweenMax.set(".box", { x: 0 });
});

read.addEventListener("change", function() {
  readVals = read.checked;
});

function normalTween() {
  var boxes = document.querySelectorAll(".box");

  TweenMax.set(".box", { x: 0 });

  for (var i = 0; i < boxes.length; i++) {
    var box = boxes[i];
    TweenMax.to(box, 2, {
      x: window.innerWidth,
      repeat: -1,
      yoyo: true
    });
  }
}

function modTween() {
  var boxes = document.querySelectorAll(".box");
  readVals = read.checked;

  TweenMax.set(".box", { x: 0 });

  for (var i = 0; i < boxes.length; i++) {
    createTween(boxes[i], readVals);
  }
}

function createTween(box, readVals) {
  var tween = TweenMax.to(box, 2, {
    x: 0,
    modifiers: {
      x: function() {
        var target;
        if (readVals) {
          target = window.innerWidth;
        } else {
          target = windowWidth;
        }

        return target * tween.ratio;
      }
    },
    repeat: -1,
    yoyo: true
  });
}

function addBoxes() {
  container.innerHTML = "";

  for (var i = 0; i < parseInt(count.value); i++) {
    var box = document.createElement("div");
    box.setAttribute("class", "box");
    container.appendChild(box);
  }
}

var stats = new Stats();

stats.showPanel(0); // 0: fps, 1: ms, 2: mb, 3+: custom
document.body.appendChild(stats.domElement);
TweenMax.set(stats.domElement, { position: "fixed", right: 0, bottom: 0 });

function animate() {
  stats.begin();

  // monitored code goes here

  stats.end();

  requestAnimationFrame(animate);
}

requestAnimationFrame(animate);

              
            
!
999px

Console