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 :: alertify js examples 
Javascript :: call c# function from javascript 
Javascript :: create file node 
Javascript :: disable a function javascript 
Javascript :: Liquid shopify 
Javascript :: what is lodash omitBy 
Javascript :: for in in javascript 
Javascript :: bs modal service angular pass data 
Javascript :: vars javascript 
Javascript :: how to get length in js without using .length method 
Javascript :: discord role giver 
Javascript :: javaScript add() Method 
Javascript :: javascript error null 
Javascript :: how to create variables using javascript 
Javascript :: css striped background 
Javascript :: render and mount functional component 
Javascript :: how-to-close-current-tab-in-a-browser-window 
Javascript :: dual array javascript 
Javascript :: images node backend server 
Javascript :: Beep sound Javascript 
Javascript :: javascript regular expression methods 
Javascript :: javascript loop array 
Javascript :: javaScript Age in Dog years //write a function that takes your age and returns it to you in dog years - they say that 1 human year is equal to seven dog years function dog Years() javaScript 
Python :: ipython autoreload 
Python :: python today - 1 day 
Python :: display maximum columns pandas 
Python :: save thing in pickle python 
Python :: cv2.cvtcolor grayscale 
Python :: how to install pyaudio 
Python :: python write json to file utf8 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =