Created
May 28, 2009 14:45
-
-
Save kent/119349 to your computer and use it in GitHub Desktop.
Add a splash of random colour to elements of your page
This file contains 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
// jQuery Colourizer | |
// Kent Fenwick 2009 | |
// Use it when you want to add a splash of random colour to your page | |
// Create the colour array | |
var color_array = ["#ce521d","#ca4b89","#006b89","#3e2d7e","#61902c", "#faa31a", "#6e002a", "#4981b3", | |
"#980069", "#2dacbf", "#ee1d25", "#9cb46f", "#9a869e", "#ee008c", "#00a895", | |
"#7b181a", "#ffd63c", "#b46638", "#bcd634", "#f4ea00", "#32b6c0", "#e8ac1c", | |
"#ea2d50", "#3c7022", "#0085cc", "#97C83B"]; | |
// Pick a random colour of the array | |
var random_color = color_array[Math.floor(Math.random()*color_array.length)]; | |
// Choose some jQuery CSS selectors of elements whose colour you want to change | |
var colour_selectors = [".manifesto li", "a.work", "#books h2", "div.work-item a", ".news-item h4 a"]; | |
// Choose some jQuery CSS selectors of elements whose background colour you want to change | |
var bg_colour_selectors = ["#navigation_bar", "#navigation li"]; | |
// loop over the Colour Selectors and apply the new random color | |
jQuery.each(colour_selectors, function(i,val){ | |
// use each val and apply the colour css property | |
$(val).css("color",random_color); | |
}); | |
// loop over the Background Colour Selectors and apply the new random color | |
jQuery.each(bg_colour_selectors, function(i,val){ | |
// use each val and apply the background colour css property | |
$(val).css("background-color",random_color); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment