// Random key generator
function getRandom(min, max) {
if(min > max) return -1;
if(min == max) return min;
var r;
do r = Math.random();
while(r == 1.0);
return min + parseInt(r * (max-min+1));
}
$(document).ready(function(){
// Enable or disable hardware-acceleration
$("#hw_toggle").click(function(){
// $(".box").toggleClass("acc");
$("#stage1").toggleClass("acc");
});
// Enable buttons
$("#hw_toggle, #btn_start").prop("disabled", false);
$("#btn_start").click(function(){
// Disable buttons
$("#hw_toggle, #btn_start").prop("disabled", true);
$("#info").css("display", "inline");
// Prepare animation
var use_hw_acc = $('#hw_toggle').attr('checked');
$(".box").each(function(){
var box = this;
var rand = getRandom(0, 5000); // Don't let all boxes start at the same time
setTimeout(function(){
// Start animation for the current box
$(box).css({
"top": "145px"
});
}, rand);
});
});
// Init mini boxes
var max = 4000;
var w = 300;
for (var i=0; i<max; i++){
var left = i;
if (left>w-5){
left = left % (w-5);
}
$('#stage1').append('<div class="box" style="left: ' + left +'px;"></div>');
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.