Pen Settings



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


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


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.


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.


                <div class="box">
  <div class="title">60 fps:</div>
  <div class="div green" id="div1"></div>

<div class="box">
  <div class="title">30 fps:</div>
  <div class="div red" id="div2"></div>

<div class="box">
  <div class="title">10 fps:</div>
  <div class="div blue" id="div3"></div>


                body {
  padding: 20px;
  background: #f2f2f2;
  width: 100%;
  height: 200px;
  position: relative;
.div {
    line-height: 100px;
    text-align: center;
    background: #fff;
    box-shadow: 0 10px 20px rgba(0,0,0,0.5);
    position: absolute;

.green {
    background-color: green;

.red {
    background-color: red;

.blue {
    background-color: blue;


                function moveDivTimeBasedImprove(div, fps) {
        var left = 0;
        var current = +new Date;
        var previous = +new Date;
        var dt = 1000 / 60;
        var acc = 0;
        var param = 1;

        function loop() {
            var current = +new Date;
            var passed = current - previous;
            previous = current;
            acc += passed; // 累积过去的时间
            while(acc >= dt) { // 当时间大于我们的固定的时间片的时候可以进行更新
                update(dt); // 分片更新时间
                acc -= dt;

        function update (dt) {
            left += param * (dt * 0.12);
            if (left > 300) {
                left = 300;
                param = -1;
            } else if (left < 0) {
                left = 0;
                param = 1;

        function draw() {
   = left + "px";

        setInterval(loop, 1000 / fps);

moveDivTimeBasedImprove(document.getElementById("div1"), 60);
moveDivTimeBasedImprove(document.getElementById("div2"), 30);
moveDivTimeBasedImprove(document.getElementById("div3"), 10);