Created
June 4, 2014 00:13
-
-
Save angelbotto/c100674540d8b8347905 to your computer and use it in GitHub Desktop.
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
$.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