Skip to content

Instantly share code, notes, and snippets.

@starzonmyarmz
Created January 10, 2011 15:59
Show Gist options
  • Save starzonmyarmz/772945 to your computer and use it in GitHub Desktop.
Save starzonmyarmz/772945 to your computer and use it in GitHub Desktop.
Function that picks a random hue for site colors on http://iamdanielmarino.com
(function colorScheme() {
var h = Math.floor(Math.random() * 360), // Hue
// Border Sides
sides = ["top", "right", "bottom", "left"],
// Elements
backgroundColor = ["#doily span", "#content h3", "nav h3", "#bg_color"],
color = ["a:not(#social a)", "#doily b"],
borderColor = ["#page_header", "#doily", "#content h3"],
// Misc Variables
a, i;
// Changes "background-color" and "color" properties
function changeColor(element, property) {
a = 1, // No transparency
l = 25; // Darker colors for text elements
try {
if (property !== "color") {
a = $(element).css(property).split(",")[3].replace(")",""),
l = 50;
}
$(element).css(property, "hsla("+ h +", 100%, "+ l +"%, " + a + ")");
}
catch(e) {}
}
// Changes Border color property
function changeBorderColor(element) {
for (var bs = 0; bs < sides.length; bs++) {
try {
a = $(element).css("border-"+sides[bs]+"-color").split(",")[3].replace(")","");
$(element).css("border-"+sides[bs]+"-color", "hsla("+ h +", 100%, 50%, "+ a +")");
}
catch(e) {}
}
}
for (i = 0; i < backgroundColor.length; i++ ) {
changeColor(backgroundColor[i], "background-color");
}
for (i = 0; i < color.length; i++ ) {
changeColor(color[i], "color");
}
for (i = 0; i < borderColor.length; i++ ) {
changeBorderColor(borderColor[i]);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment