Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Randomise the colour of every element on the page every 5000ms
- * Just for fun.
- *
- * @author Caelan Stewart
- */
- setInterval(function() {
- var count = 0;
- function chaos(element) {
- // Check that this element is standard element, and not a text node or some other kind
- if(element.nodeType === 1) {
- var childNodesLen = element.childNodes.length,
- iter;
- // Generate random colour
- element.style.backgroundColor = '#' + ((1 << 24) * Math.random() | 0).toString(16);
- // Iterate through children and self-invoke this function for each child element.
- for(iter = 0; iter < childNodesLen; ++iter) {
- chaos(element.childNodes[iter]);
- }
- count++;
- }
- }
- var start = Date.now();
- chaos(document.body);
- console.log('Took: ' + (Date.now() - start) + 'ms');
- console.log('Elements: ' + count);
- }, 5000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement