Skip to content

Instantly share code, notes, and snippets.

@dkordik
Created January 19, 2012 22:34
Show Gist options
  • Save dkordik/1643367 to your computer and use it in GitHub Desktop.
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
//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);
@WinHack9702GitHub
Copy link

WinHack9702GitHub commented Apr 12, 2023

//concept from http://www.sitepoint.com/multi-threading-javascript/

var $visibleElements = $(":visible");

var random255 = function () {
    return Math.floor(Math.random()*99999);
}
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 > 1000000) {
        clearInterval(intervalId);
    }
    doWork();
    i++;
},1);

MODIFED VERSION.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment