Created
January 19, 2012 22:34
-
-
Save dkordik/1643367 to your computer and use it in GitHub Desktop.
Seizure.js - experiment in doing more UI manipulation in JS than a "stop script?" limit would allow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//concept from http://www.sitepoint.com/multi-threading-javascript/ | |
var $visibleElements = $(":visible"); | |
var random255 = function () { | |
return Math.floor(Math.random()*255); | |
} | |
var randomColor = function () { | |
return "rgb(" + random255() + "," + random255() + "," + random255() + ")"; | |
} | |
var doWork = function () { | |
$visibleElements.each(function () { | |
$(this).css("backgroundColor",randomColor()); | |
}); | |
} | |
// //UI-blocking version, page will stop responding | |
// for(var i=0; i<=10000; i++) { | |
// doWork(); | |
// } | |
//Non-UI-blocking version | |
var i=0; | |
var intervalId = setInterval(function () { | |
if (i > 10000) { | |
clearInterval(intervalId); | |
} | |
doWork(); | |
i++; | |
},1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
MODIFED VERSION.