Con jQuery possiamo regolare il colore del testo di un elemento in base al colore del suo sfondo.
La soluzione รจ la seguente:
(function( $ ) {
$.fn.adjustColor = function() {
return this.each(function() {
var $el = $( this );
var rgb = $el.css( "background-color" ).replace( "rgb(", "" ).replace( ")", "" ).split( "," ).map( Number );
var o = Math.round( ( ( rgb[0] * 299 ) + ( rgb[1] * 587 ) + ( rgb[2] * 114 ) ) /1000 );
if( o > 125 ) {
$el.css( "color", "#000" );
} else {
$el.css( "color", "#fff" );
}
});
};
})( jQuery );