Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

rgb to hex javascript

// Convert RGB to Hex
function getColorFun(r, g, b) {
   return '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
}

getColorFun(178, 232, 55);
// The output here is #b2e837
Comment

javascript convert hex color to rgb

function rgbToHex(r, g, b) {
  return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
}

function hexToRgb(hex, result = /^#?([a-fd]{2})([a-fd]{2})([a-fd]{2})$/i.exec(hex)) {
  return result ? result.map(i => parseInt(i, 16)).slice(1) : null
  //returns [23, 14, 45] -> reformat if needed
}

console.log(rgbToHex(10, 54, 120)); // #0a3678
console.log(hexToRgb("#0a3678")); // [10, 54, 120]
Comment

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

PREVIOUS NEXT
Code Example
Javascript :: get lines as list from file node js 
Javascript :: setinterval in angular 6 
Javascript :: raspberry pi install node js 
Javascript :: jquery toggle attribute disabled 
Javascript :: firstElementChild jquery equivalent 
Javascript :: create a new input with type checkbox javascript 
Javascript :: navigate to url javascript 
Javascript :: add class queryselector 
Javascript :: find in highest value key from an object javascript 
Javascript :: how to find index of max number in js 
Javascript :: await settimeout 
Javascript :: Delete icon Mui 
Javascript :: jquery insert element as first child 
Javascript :: string to number angularjs 
Javascript :: Install Vue + Laravel 8 
Javascript :: image touchable opacity react native 
Javascript :: select2 disable search 
Javascript :: Masonry js cdn 
Javascript :: jquery change font color 
Javascript :: onclick prevent default 
Javascript :: convert c to javascript 
Javascript :: textField space between text flutter 
Javascript :: stop propagation event 
Javascript :: convert/replace space to dash/hyphen javascript 
Javascript :: how to open link in new tab in react js 
Javascript :: js random number between 1 and 10 
Javascript :: To install the latest version of React: 
Javascript :: how to update node js version 
Javascript :: dont drag img 
Javascript :: moment is not defined 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =