Skip to content

Instantly share code, notes, and snippets.

@angelbotto
Created June 4, 2014 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angelbotto/c100674540d8b8347905 to your computer and use it in GitHub Desktop.
Save angelbotto/c100674540d8b8347905 to your computer and use it in GitHub Desktop.
$.fn.textkolor = function(str) {
var hash = 0;
for (var i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
var colour="#";
for (var j = 0; j < 3; j++) {
var value = (hash >> (j * 8)) & 0xFF; colour += ('00' + value.toString(16)).substr(-2);
}
this.css("background", colour );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment