Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

convert hex code to rgb javascript

function hexToRgb(hex){
	var result = /^#?([a-fd]{2}])([a-fd]{2})([a-fd]{2})$/i.exec(hex);
  	
 	return result ? {
    	r: parseInt(result[1],  16);
      	g: parseInt(result[2],  16);
  		b: parseInt(result[3],  16);
    } : null;
}
var hex = "#0a3678";
console.log(hexToRgb(hex).r+","+hexToRgb(hex).g+","+hexToRgb(hex).b);//10,54,120
Comment

hexstring to rgb array js

function hexToRgb(hex) {
  // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
  var shorthandRegex = /^#?([a-fd])([a-fd])([a-fd])$/i;
  hex = hex.replace(shorthandRegex, function(m, r, g, b) {
    return r + r + g + g + b + b;
  });

  var result = /^#?([a-fd]{2})([a-fd]{2})([a-fd]{2})$/i.exec(hex);
  return result ? [
    parseInt(result[1], 16),
    parseInt(result[2], 16),
    parseInt(result[3], 16)
  ] : null;
}

alert(hexToRgb("#0033ff").g); // "51";
alert(hexToRgb("#03f").g); // "51";
Comment

PREVIOUS NEXT
Code Example
Javascript :: delete axios token 
Javascript :: dayjs tostring 
Javascript :: jasmine spy return value when using create Spy Object angular 2 
Javascript :: add json object to json array javascript 
Javascript :: angular build production 
Javascript :: angular print json 
Javascript :: move first element to last javascript 
Javascript :: reset form input react 
Javascript :: timeout 
Javascript :: next js page loader 
Javascript :: php watermark facile 
Javascript :: make object to array javascript 
Javascript :: js dictionary to extract the same key bvalues 
Javascript :: how to run an existing react project 
Javascript :: nodejs open file 
Javascript :: javascript websocket example code 
Javascript :: moment to javascript date 
Javascript :: text overflow ellipsis two lines react native 
Javascript :: java json string to map 
Javascript :: react context 
Javascript :: copy paste menu react native textinput disable 
Javascript :: get the value of css pseudo properties js 
Javascript :: mapdispatchtoprops 
Javascript :: javascript array remove middle 
Javascript :: jest listen EADDRINUSE: address already in use :::5000 jest 
Javascript :: react bootstrap font awesome icons 
Javascript :: how to check whether a string contains a substring in javascript 
Javascript :: jquery fadeout to fadein 
Javascript :: dynamic imports js 
Javascript :: how to get type of variable in javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =