Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

convert hex to rgba with opacity

//convert hex to rgba with opacity
function addAlpha(color, opacity) {
    // coerce values so ti is between 0 and 1.
    var _opacity = Math.round(Math.min(Math.max(opacity || 1, 0), 1) * 255);
    return color + _opacity.toString(16).toUpperCase();
}
addAlpha('FF0000', 1); // returns 'FF0000FF'
addAlpha('FF0000', 0.5); // returns 'FF000080'
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #convert #hex #rgba #opacity
ADD COMMENT
Topic
Name
2+1 =