/ Published in: jQuery
URL: headloose.com
a jQuery function to set a class depending on whether it is high or low contrast
Expand |
Embed | Plain Text
$.fn.contrast = function (cl1, cl2) { var m, yiq; return this.each(function () { m = $(this).css('background-color').match(/^\D+(\d+)\D+(\d+)\D+(\d+)\D+(?:([\d\.]+)\D+)?$/); if(c.transparent !== true) { yiq = ((m[1]*299)+(m[2]*587)+(m[3]*114))/1000; $(this).addClass(((yiq >= 128) ? cl1 : cl2)); } else { $(this).addClass(cl1); } }); };
You need to login to post a comment.
