Random colors for tags
-
Random Colors?!? That's my jam!
$(document).ready(function(){ var letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']; $('[data-tag]').each(function () { var $tag = $(this); var tag = $tag.attr('data-tag'); var x = tag.charAt(0) || 'm'; var y = tag.charAt(1) || 'm'; var z = tag.charAt(2) || 'm'; x = x.toLowerCase(); y = y.toLowerCase(); z = z.toLowerCase(); x = letters.indexOf(x); y = letters.indexOf(y); z = letters.indexOf(z); x = x === -1 ? 12 : x; y = y === -1 ? 12 : y; z = z === -1 ? 12 : z; var hue = (x * 14 + z * 14) % 360; var sat = 100 - z * 2; var lum = 64 - y; var color = 'hsl('+hue+','+sat+'%,'+lum+'%)'; $tag.css('color', color); }); });
Totally adding this to Rainbows!
Copyright © 2024 NodeBB | Contributors