css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <link href='//fonts.googleapis.com/css?family=Signika+Negative:300,400,700' rel='stylesheet' type='text/css'>
<div id="demo">
<div id="controls">
	<form id="form">
        <li style="padding-left:16px;">
            Engine:
            <select id="engine" size="1">
                <option value="jquery">jQuery 3 (JS)</option>
                <option value="gsap">GSAP (JS)</option>
                <option value="anime">anime (JS)</option>
                <option value="webanimations" class="webanimations">Web Animations (JS)</option>
                <option value="zepto">Zepto (CSS)</option>
            </select>
        </li>
        <li>
            Properties:
            <select id="properties" size="1">
              <option value="normal">top, left, width, height</option>
              <option value="transforms">transform:translate(...) scale(...)</option>
            </select>
        </li>
    	  <li>
            Dots:
            <select id="dotQuantity" size="1">
                <option value="25">25</option>
                <option value="50">50</option>
                <option value="100">100</option>
                <option value="200">200</option>
                <option value="300">300</option>
                <option value="400">400</option>
                <option value="500" selected="selected">500</option>
                <option value="750">750</option>
                <option value="1000">1000</option>
                <option value="1250">1250</option>
                <option value="1500">1500</option>
                <option value="2000">2000</option>
                <option value="2500">2500</option>
                <option value="3000">3000</option>
            </select>
        </li>
        <li style="vertical-align:bottom;"><div id="start">START</div></li>
        <li id="tardy" style="flex-grow:3;color: #fcd000;"></li>
        <li id="fps">-- fps</li>
    </form>
</div>
<div id="field">
  <div id="instructions"><h1>HTML5 Animation Speed Test</h1>
    <p>Compare the animation performance of <a href="https://www.jquery.com">jQuery</a>, <a href="https://greensock.com/gsap-js/">GSAP</a> (GreenSock Animation Platform), <a href="http://anime-js.com">anime</a>, <a href="https://w3c.github.io/web-animations/">Web Animations (WAAPI)</a>, and CSS Transitions (which are what <a href="http://www.zeptojs.com">Zepto</a> uses). Select the options above and click "START". Crank up the number of dots until you see jerky behavior or clumps/rings. Also notice which properties animate faster: "top", "left", "width" and "height" or "transform: translate(...) scale(...)". You may be surprised.</p><p>If any animation completes <strong>more than 150ms</strong> later than it was supposed to, it will be logged and shown in orange
    text next to the START/STOP button along with the average amount of time they blew past their schedued end time.
    This is important because some engines may have an illusion of being smoother but in reality their internal timing mechanisms are drifting and everything is slowing down, thus there's less movement between each frame. For example, a tween that's supposed to take 750ms may actually end up taking 10,000ms to complete. </p></div>
</div>
</div>

            
          
!
            
              body {
  background-color: black;
  margin:0;
  padding:0;
  color:#eee;
  font-family: Signika Negative, sans-serif;
  font-weight: 300;
  font-size: 1.15em;
  user-select:none;
  -webkit-user-select:none;
}
html, body {
  height: 100%;
  overflow:hidden;
}
h1 {
  font-weight: 400;
  font-size:2em;
  line-height:1em;
  margin-bottom:0.1em;
  color: white;
}
a, a:hover, a:visited {
  color:#71B200;
}
#controls {
  display:table-row;
  background-color:#555;
  background: linear-gradient(to bottom,  #777 0%,#444 100%);
  padding:10px 10px 10px 5px;
  z-index:1000;
}
#controls form li {
  display:table-cell;
  padding:12px 6px 10px 6px;
  vertical-align:middle;
  text-shadow: 1px 1px 1px #000;
}
#instructions {
  width:82%;
  margin-left:8%;
  padding-top:1em;
  line-height: 1.5em;
  color:#ccc;
  pointer-events: auto;
}
#demo {
  display:table;
  width:100%;
  height:100%;
}
#field {
  position:relative;
  display:table-cell;
  width:100%;
  height: 100%;
  overflow:hidden;
  z-index:-100;
  border-top: 1px solid #777;
  pointer-events:none;
}
#start {
  color: black;
  border-radius: 6px;
  padding: 5px 18px;
  border: 2px solid black;
  background: #9af600;
  background: linear-gradient(to bottom,  #9af600 0%,#71B200 100%);
  cursor: pointer;
  text-shadow: none;
  font-weight: 400;
}
#controls #fps {
  text-shadow: none;
  background-color: #CCC;
  padding: 6px;
  margin-right: 14px;
  color: #CC0000;
  border-radius: 5px;
  border-color: #000000;
  border-style: solid;
  border-width: 1px;
  font-size: 24px;
}
#form {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}
strong {
  color: white;
}
            
          
!
            
              var $start = $("#start"),
    $dotQtyInput = $("#dotQuantity"),
    $engineInput = $("#engine"),
    $propertiesInput = $("#properties"),
    $instructions = $("#instructions"),
    $field = $("#field"),
    $window = $(window),
    $inputs = $("select"),
    fps = document.getElementById("fps"),
    inProgress = false,
    tests = {},
    tardy = document.getElementById("tardy"),
    ticker = TweenLite.ticker,
    count = 0,
    tardyTotal = 0,
    tardyCount = 0,
		lastTardyReport = 0,
    duration, radius, centerX, centerY, dots, rawDots, currentTest,  startingCSS, prevUpdate, startTime, startFrame, fpsActive;

/**
 * The goal of this test is to compare how various animation engines perform under pressure, taking relatively common
 * animation tasks and running a lot of them at once to see raw performance. The goal is NOT to figure out the most
 * efficient way to move dots in a starfield pattern.
 *
 * The same code drives everything except the actual tweens themselves. Every test in the "tests"
 * object has 4 properties:
 *
 * 		- milliseconds [boolean] - true if the duration should be defined in milliseconds
 *
 * 		- wrapDot [function] - when each dot <img> is created, it is passed to the wrapDot() method
 * 							   and whatever is returned gets stored in the array of dots to tween. This
 * 							   is useful to improve performance of things like jQuery because
 * 							   instead of passing the dom element to the tween() method (which would require
 * 							   jQuery to then query the dom and wrap the element in an engine-specific object
 * 							   before calling animate() on it), a native object can be used. Basically it lets you
 * 							   cache the dot's wrapper for better performance.
 *
 * 		- tween [function] - This is the core of the whole test. tween() is called for each dot, and the dot is
 * 							 passed as a parameter. The tween() function should set the dot's cssText to the
 * 							 startingCSS value (which just places the dot in the middle of the screen and sets its
 * 							 width/height to 1px) and then after a random delay between 0 and the duration of the tween,
 * 							 it should tween the dot at a random angle, altering either the left/top values or transform
 * 							 translate() values accordingly, and adjust the size to 32px wide/tall using either 
 * 							 width/height or transform:scale(). Then, after the tween is done, it should call the tween()
 * 							 method again for that dot. So the same dot will just continuously tween outward from the
 * 							 center at random angles and at random delay values.
 *
 * 		- stop [function] - This function is called when the user stops the test. The dot is passed as a parameter.
 * 							The function should immediately stop/kill the tween(s) of that dot (or all dots - that's fine too).
 *
 *  - nativeSize [Boolean] - true if the beginning width/height of the image should be its native size
 *                          (typically necessary for transforms, but not when we're animating width/height).
 *
 * I don't claim to be an expert at the various other animation engines out there, so if there are optimizations
 * that could be made to make them run better, please let me know. I tried to keep things as fair as possible.
 **/

//jQuery normal (top/left/width/height)
tests.jquery_normal = {
  milliseconds:true,
  wrapDot:function(dot) {
    return jQuery(dot); //wrap the dot in a jQuery object in order to perform better (that way, we don't need to query the dom each time we tween - we can just call animate() directly on the jQuery object)
  },
  tween:function(dot) {
    var delay = checkTardyAndGetDelay(dot);
    var angle = Math.random() * Math.PI * 2;
    dot[0].style.cssText = startingCSS;
    dot.delay(delay).animate({left:Math.cos(angle) * radius + centerX,
                                                 top:Math.sin(angle) * radius + centerY,
                                                 width:32,
                                                 height:32}, duration, "cubicIn", function() { tests.jquery_normal.tween(dot) });
  },
  stop:function(dot) {
    dot.stop(true);
  },
  nativeSize:false
};

//GSAP normal (top/left/width/height)
tests.gsap_normal = {
  milliseconds:false,
  wrapDot:function(dot) {
    return dot; //no wrapping necessary
  },
  tween:function(dot) {
    var delay = checkTardyAndGetDelay(dot);
    var angle = Math.random() * Math.PI * 2;
    dot.style.cssText = startingCSS;
    TweenLite.to(dot, duration, {css:{left:Math.cos(angle) * radius + centerX,
                                      top:Math.sin(angle) * radius + centerY,
                                      width:32,
                                      height:32},
                                 delay:delay,
                                 ease:Cubic.easeIn,
                                 overwrite:"none",
                                 onComplete:tests.gsap_normal.tween,
                                 onCompleteParams:[dot]});
  },
  stop:function(dot) {
    TweenLite.killTweensOf(dot);
  },
  nativeSize:false
};

//GSAP transforms (translate()/scale())
tests.gsap_transforms = {
  milliseconds:false,
  wrapDot:function(dot) {
    return dot; //no wrapping necessary
  },
  tween:function(dot) {
    var delay = checkTardyAndGetDelay(dot);
    var angle = Math.random() * Math.PI * 2;
    TweenLite.set(dot, {css:{x:0, y:0, scale:0.06, force3D:true}, overwrite:"none"});
    TweenLite.to(dot, duration, {css:{x:(Math.cos(angle) * radius),
                                      y:(Math.sin(angle) * radius),
                                      scaleX:2,
                                      scaleY:2},
                                 delay:delay,
                                 ease:Cubic.easeIn,
                                 overwrite:"none",
                                 onComplete:tests.gsap_transforms.tween,
                                 onCompleteParams:[dot]});
  },
  stop:function(dot) {
    TweenLite.killTweensOf(dot);
  },
  nativeSize:true
};


//Anime top/left/width/height
tests.anime_normal = {
	milliseconds:true,
	wrapDot:function(dot) {
		return dot; //no wrapping necessary
	},
	tween:function(dot) {
    var delay = checkTardyAndGetDelay(dot);
		var angle = Math.random() * Math.PI * 2;
		dot.style.cssText = startingCSS;
		anime({targets:dot, duration:duration,
			left:Math.cos(angle) * radius + centerX,
			top:Math.sin(angle) * radius + centerY,
			width:32,
			height:32,
			delay:delay,
			easing:"easeInCubic",
			complete:function() {
				tests.anime_normal.tween(dot);
			}});
	},
	stop:function(dot) {
		anime.remove(dot);
	},
	nativeSize:false
};

//Anime transforms
tests.anime_transforms = {
	milliseconds:true,
	wrapDot:function(dot) {
		return dot; //no wrapping necessary
	},
	tween:function(dot) {
    var delay = checkTardyAndGetDelay(dot);
		dot.style.cssText = "position:absolute; top:" + centerY + "px; left:" + centerX + "px; transform: none;";
		//anime({targets:dot, position:"absolute", top:centerY, left:centerX, translateX:0, translateY:0, scale:1, duration:0}); //zero-duration animations don't seem to work. Had to set cssText instead (above).
		var angle = Math.random() * Math.PI * 2;
		anime({targets:dot, duration:duration,
			translateX:(Math.cos(angle) * radius),
			translateY:(Math.sin(angle) * radius),
			scale:32,
			delay:delay,
			easing:"easeInCubic",
			complete:function() {
				tests.anime_transforms.tween(dot);
			}});
	},
	stop:function(dot) {
		anime.remove(dot);
	},
	nativeSize:false
};


//Web Animations
tests.webanimations_normal = {
	milliseconds:true,
	wrapDot:function(dot) {
		return dot; //no wrapping necessary
	},
	tween:function(dot) {
    var delay = checkTardyAndGetDelay(dot);
		dot.style.cssText = startingCSS;
		var angle = Math.random() * Math.PI * 2,
			anim = dot.anim = dot.animate([{left:centerX + "px", top:centerY + "px", width:"1px", height:"1px"}, {
					left:(Math.cos(angle) * radius + centerX) + "px",
					top:(Math.sin(angle) * radius + centerY) + "px",
					width:"32px",
					height:"32px"
				}], {duration: duration, delay: delay, fill:"forwards", easing:"cubic-bezier(0.550, 0.055, 0.675, 0.190)"});
		anim.onfinish = function() {
			tests.webanimations_normal.tween(dot);
		};
	},
	stop:function(dot) {
		dot.anim.onfinish = null; //otherwise it'll call the onfinish when cancelled, and the loop will continue.
		dot.anim.cancel();
	},
	nativeSize:false
};

//Web Animations (transforms)
tests.webanimations_transforms = {
	milliseconds:true,
	wrapDot:function(dot) {
		return dot; //no wrapping necessary
	},
	tween:function(dot) {
    var delay = checkTardyAndGetDelay(dot);
		dot.style.cssText = startingCSS + " transform: scale(0.06); -webkit-transform: scale(0.06);";
		var angle = Math.random() * Math.PI * 2,
			anim = dot.anim = dot.animate([{transform:"translate(0px, 0px) scale(0.06)"}, {
					transform:"translate(" + (Math.cos(angle) * radius) + "px, " + (Math.sin(angle) * radius) + "px) scale(2)"
				}], {duration: duration, delay: delay, fill:"forwards", easing:"cubic-bezier(0.550, 0.055, 0.675, 0.190)"});
		anim.onfinish = function() {
			tests.webanimations_transforms.tween(dot);
		};
	},
	stop:function(dot) {
		dot.anim.onfinish = null; //otherwise it'll call the onfinish when cancelled, and the loop will continue.
		dot.anim.cancel();
	},
	nativeSize:true
};



//Zepto normal (top/left/width/height)
tests.zepto_normal = {
  milliseconds:true,
  wrapDot:function(dot) {
    return Zepto(dot); //wrap the dot in a jQuery object in order to perform better (that way, we don't need to query the dom each time we tween - we can just call animate() directly on the jQuery object)
  },
  tween:function(dot) {
    var delay = checkTardyAndGetDelay(dot);
    var angle = Math.random() * Math.PI * 2;
    dot[0].style.cssText = startingCSS;
    //Zepto's delay feature performs TERRIBLY under pressure, so we use a setTimeout() instead to improve performance.
    setTimeout(function() {
      if (!dot.isKilled) { //Zepto doesn't have a feature that allows us to kill tweens, so we simply set our own "isKilled" property to true when the tween is supposed to be killed and then stop the recursion thereafter which gives us a somewhat similar effect.
        dot.animate({left:Math.cos(angle) * radius + centerX,
                     top:Math.sin(angle) * radius + centerY,
                     width:32,
                     height:32}, duration, "cubic-bezier(0.550, 0.055, 0.675, 0.190)", function() { tests.zepto_normal.tween(dot) });
      }
    }, delay);
  },
  stop:function(dot) {
    dot.isKilled = true;
  },
  nativeSize:false
};

//Zepto transforms (translate()/scale())
tests.zepto_transforms = {
  milliseconds:true,
  wrapDot:function(dot) {
    return Zepto(dot); //wrap the dot in a jQuery object in order to perform better (that way, we don't need to query the dom each time we tween - we can just call animate() directly on the jQuery object)
  },
  tween:function(dot) {
    var delay = checkTardyAndGetDelay(dot);
    //I couldn't just set the css() reliably with Zepto (it failed), so I was forced to use a zero-duration animate() call. It's fair, though, because we actually do a zero-duration tween for TweenLite too.
    dot.animate({translateX:"0px", translateY:"0px", rotateY:"0rad", rotateX:"0rad", scale:"0.06,0.06"},0);
    //Zepto's delay feature performs TERRIBLY under pressure, so we use a setTimeout() instead to improve performance.
    setTimeout(function() {
      if (!dot.isKilled) { //Zepto doesn't have a feature that allows us to kill tweens, so we simply set our own "isKilled" property to true when the tween is supposed to be killed and then stop the recursion thereafter which gives us a somewhat similar effect.
        var angle = Math.random() * Math.PI * 2;
        dot.animate({translateX:(Math.cos(angle) * radius) + "px",
                     translateY:(Math.sin(angle) * radius) + "px",
                     scale:"2,2",
                     delay:delay}, duration, "cubic-bezier(0.550, 0.055, 0.675, 0.190)", function() { tests.zepto_transforms.tween(dot); });
      }
    }, delay);
  },
  stop:function(dot) {
    dot.isKilled = true;
  },
  nativeSize:true
};


function toggleTest() {
  var i, size;
  inProgress = !inProgress;
  if (inProgress) {
    $inputs.prop("disabled", true);
    $field.css({pointerEvents:"none"}); //improve performance - ignore pointer events during animation
    $start.html(" STOP ");
    $start.css({background:"#C00"});
    
    startTime = prevUpdate = ticker.time;
		startFrame = ticker.frame;
    tardyTotal = tardyCount = count = 0;
		tardy.innerHTML = "Overdue animations: 0% (0ms average, 0%)";
    fps.innerHTML = "-- fps";
    fps.style.backgroundColor = "#FFFFFF";
    fps.style.borderColor = fps.style.color = "#FF0000";
    fps.style.borderWidth = "3px";
    fps.style.paddingTop = fps.style.paddingBottom = "4px";
    TweenLite.delayedCall(1, activateFPS); //wait a little bit to allow the dots to fill the screen before starting to report the FPS
    
    TweenLite.to($instructions, 0.7, {autoAlpha:0, overwrite:"all"});
    currentTest = tests[$engineInput.val() + "_" + $propertiesInput.val()];
    size = (currentTest.nativeSize ? "16px" : "1px");
    centerX = $field.width() / 2;
    centerY = $field.height() / 2;
    startingCSS = "position:absolute; left:" + centerX + "px; top:" + centerY + "px; width:" + size + "; height:" + size + ";";
    radius = Math.sqrt(centerX * centerX + centerY * centerY);
    duration = currentTest.milliseconds ? 750 : 0.75;
    //we wait a millisecond before creating the dots and starting to animate them so that the UI renders first (making the "start" button say "stop"), otherwise users could be confused when there's a long pause when you choose Zepto and transforms due to the fact that it can take a while for the browser to put all the dots on their own layers.
    setTimeout(function() {
      createDots();
      i = dots.length;
      while (--i > -1) {
        currentTest.tween(dots[i]);
      }
    }, 1);
    
  } else {
    $start.html(" START ");
    $start.css({backgroundColor:"#9af600", background: "linear-gradient(to bottom, #9af600 0%,#71B200 100%"});
    TweenLite.to($instructions, 0.7, {autoAlpha:1, delay:0.2});
    $inputs.prop("disabled", false);
    calibrateInputs();
    $field.css({pointerEvents:"auto"});
    //stop the tweens and remove the dots.
    i = dots.length;
    while (--i > -1) {
      currentTest.stop(dots[i]);
      $field[0].removeChild(rawDots[i]); //removes dot(s)
    }
    dots = null;
    rawDots = null;
    
    fps.style.backgroundColor = "#CCCCCC";
    fps.style.color = "#CC0000";
    fps.style.borderColor = "#000000";
    fps.style.borderWidth = "1px";
    fps.style.paddingTop = fps.style.paddingBottom = "6px";
    fpsActive = false;
    TweenLite.killTweensOf(activateFPS);
    //clearInterval(fpsIntervalID);
    TweenLite.ticker.removeEventListener("tick", activateFPS);
  }
}

function createDots() {
  var i = parseInt($dotQtyInput.val()),
      dot;
  dots = [];
  rawDots = [];
  while (--i > -1) {
    dot = document.createElement("img");
    dot.src = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/16327/dot.png";
    dot.width = 1;
    dot.height = 1;
    dot.id = "dot" + i;
    dot.style.cssText = startingCSS;
    $field[0].appendChild(dot);
    rawDots.push(dot);
    dots.push(currentTest.wrapDot(dot));
  }
}

function calibrateInputs(e) {
  if ($engineInput.val() === "jquery") { //jQuery cannot animate transforms without a 3rd party plugin, so disable that option
    $propertiesInput[0].selectedIndex = 0;
    $propertiesInput.prop("disabled", true);
  } else {
    $propertiesInput.prop("disabled", false);
  }
}

$start.click(toggleTest);
$inputs.change(calibrateInputs);

jQuery.easing.cubicIn = $.easing.cubicIn = function(p, n, firstNum, diff) { //we need to add the standard CubicIn ease to jQuery
  return firstNum + p * p * p * diff;
}
jQuery.fx.interval = 16; //ensures that jQuery refreshes at roughly 60fps like GSAP and the others to be more even/fair.
$propertiesInput.prop("disabled", true);




function activateFPS() {
  fpsActive = true;
  frames = 0;
  lastUpdate = getTime();
  //originally we used setInterval() to keep things generic, but certain browsers got REALLY slow, updating requestAnimationFrame() far more frequently under stress, so I switched to GSAP's ticker to make things more consistent (which actually makes the other engines look BETTER, not worse). 
  //fpsIntervalID = setInterval(updateFPS, 10);
  TweenLite.ticker.addEventListener("tick", updateFPS);
}

var getTime = Date.now || function() {return new Date().getTime();}, 
    lastUpdate, frames, fpsIntervalID;

function updateFPS() {
  frames++;
  var elapsed = getTime() - lastUpdate;
  if (fpsActive && elapsed > 1000) {
    fps.innerHTML = Number(frames / elapsed * 1000 ).toFixed(1) + " fps";
    lastUpdate += elapsed;
    frames = 0;
  }
}

function checkTardyAndGetDelay(dot) {
  var delay = Math.random() * duration,
      now = Date.now();
  if (now - dot.due > 150) { //if the animation is more than 150ms late, consider it overdue and report it. 
    reportTardy(now - dot.due);
  } else if (tardyCount && now - lastTardyReport > 1500) { //make sure the tally is updated at least every second.
    var average = Math.round(tardyTotal / tardyCount);
    tardy.innerHTML = "Overdue animations: " + Math.ceil(tardyCount * 100 / count) + "% (" + average + "ms average, " + Math.round(average * 100 / 750) + "%)";
    lastTardyReport = now;
  }
  dot.due = now + (delay + duration) * (currentTest.milliseconds ? 1 : 1000);
  count++;
  return delay;
}

function reportTardy(amount) {
  tardyTotal += amount;
  tardyCount++;
  lastTardyReport = Date.now();
  var average = Math.round(tardyTotal / tardyCount);
  tardy.innerHTML = "Overdue animations: " + Math.ceil(tardyCount * 100 / count) + "% (" + average + "ms average, " + Math.round(average * 100 / 750) + "%)";
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console