Search
 
SCRIPT & CODE EXAMPLE
 

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'
Comment

white with opacity rgba to hex

function hexify(color) {
  var values = color
    .replace(/rgba?(/, '')
    .replace(/)/, '')
    .replace(/[s+]/g, '')
    .split(',');
  var a = parseFloat(values[3] || 1),
      r = Math.floor(a * parseInt(values[0]) + (1 - a) * 255),
      g = Math.floor(a * parseInt(values[1]) + (1 - a) * 255),
      b = Math.floor(a * parseInt(values[2]) + (1 - a) * 255);
  return "#" +
    ("0" + r.toString(16)).slice(-2) +
    ("0" + g.toString(16)).slice(-2) +
    ("0" + b.toString(16)).slice(-2);
}

var myHex = hexify('rgba(255,255,255,0.6)'); // "#f5faf3"

console.log(myHex);
Comment

PREVIOUS NEXT
Code Example
Javascript :: rest operator in javascript 
Javascript :: material ui table row height 
Javascript :: react native dynamic style 
Javascript :: audio get current time 
Javascript :: show password using javascript 
Javascript :: root of any number javascript 
Javascript :: array js 
Javascript :: regex for ipv4 
Javascript :: empty array length javascript 
Javascript :: find the length and the last character of string in js 
Javascript :: add role command discord.js 
Javascript :: html get color gradient percentage 
Javascript :: callbacks in jquery 
Javascript :: trigger jquery autocomplete on click 
Javascript :: row append and calculation in jquery datatable 
Javascript :: useeffect loading state 
Javascript :: dark mode javascript 
Javascript :: Detect Mobile / Computer by Javascript 
Javascript :: javascript side effects 
Javascript :: node biology definition 
Javascript :: javascript startdate end date 
Javascript :: npm html-validate 
Javascript :: 188.4 - 93.1 
Python :: python request remove warning 
Python :: opencv show image jupyter 
Python :: max columns in python 
Python :: how to make a letter animation in python 
Python :: python 1 second delay 
Python :: python print traceback from exception 
Python :: pandas groupby agg count unique 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =