showing results for - "hex to rgba in js"
Julia
11 Jan 2018
1hexToRGB(hex: string, alpha: string) {
2
3  const r = parseInt(hex.slice(1, 3), 16);
4  const g = parseInt(hex.slice(3, 5), 16);
5  const b = parseInt(hex.slice(5, 7), 16);
6
7  if (alpha) {
8    return `rgba(${r}, ${g}, ${b}, ${alpha})`;
9  } else {
10    return `rgb(${r}, ${g}, ${b})`;
11  }
12}
Federica
01 Aug 2019
1//If you write your own code, remember hex color shortcuts (eg., #fff, #000)
2
3function hexToRgbA(hex){
4    var c;
5    if(/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)){
6        c= hex.substring(1).split('');
7        if(c.length== 3){
8            c= [c[0], c[0], c[1], c[1], c[2], c[2]];
9        }
10        c= '0x'+c.join('');
11        return 'rgba('+[(c>>16)&255, (c>>8)&255, c&255].join(',')+',1)';
12    }
13    throw new Error('Bad Hex');
14}
15
16hexToRgbA('#fbafff')
17
18/*  returned value: (String)
19rgba(251,175,255,1)
20*/
21
queries leading to this page
npm hex to rgbargba color jshow use rgba color javascript color propertyconvertir color hx a rgb en javascripthow to convert rgba to hex in javascriptrgba color javascriptjs rgb alpha to hexjs rgba to rgbjs background color rgbajavascript get rgba and hex colorsjavascript rgba pass hexrgba to rgb value javascriptconver rgba to hexa by javascriptjs color number to rgbajavascript rgb to rgbahow use rgba color code with javascript color propertyhexa to rgba javascripthex to rgb javascriptjs hex color to css rgbahex color to rgba colorjs hex to rgba converterjavascript hex to rgbajavascript convert hex to rgbahex to rgba jsjavascript style backgroundcolor rgbajs hex to rgbachart js rgba colorjavascript rgbajavascript convert html color code to rgbaadd alpha to rgba from hex javascripthow to give rgba color in javascripthex code to rgba javascriptjavascript set background color rgbargba to hex javascriptrgba to hex converter javascriptjavascript hex color to rgbafunction get color rgba javascriptjs hex color to rgbjavascript rgba to hexrgba color in jsconvert rgba to hex javascriptjs rgba colorjavascript hex with alpha to rgbhex color to rgba javascriptget rgba from hex javascriptrgba to hex in jsjavascript rgba string to hexbackground color rgba javascripthow to use rgba color in jsconvert a rgba color to hex in javascriptjs hex color to rgbajs rgba to hexbackground color javascript rgbacolor js rgbacolor not working with rgba in jsjs convert hex to rgbargb background color jsjquery rgba to hexget rgba to hex 8 javascripthex to rgba in jscan i convert color in rgba in javascriptjavascript rgba colorget rgba color javascriptrgba color use in javascriptjavascript css rgbargba to hex jsconvert rgba color code to hex javascriptset rgba color in javascriptcolor hex rgba codehex to rgba javascriptrgb to rgba javascripthex to rgba in js