Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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

PREVIOUS NEXT
Code Example
Javascript :: slick slider on change 
Javascript :: sort list by likes in javascript 
Javascript :: HSET redis, HINCRBYFLOAT redis 
Javascript :: Minimum Path Sum Rec 
Javascript :: angular routing appcomponent snipped 
Javascript :: before each function 
Javascript :: javascript class is not defined 
Javascript :: how to sum up the first 2 elements in an array javascript 
Javascript :: puppeteer click is not working 
Javascript :: function Using onpause and onplay Method to Start and Stop Animationto replace source file path to jpg image 
Javascript :: jquery code convert into javascript online 
Javascript :: add image to center in canvas 
Javascript :: menu with dynamic submenu in javascript 
Javascript :: style mapbox paint data driven 
Javascript :: how to get a set of values in mogodb 
Javascript :: samesite cookies/console.log 
Javascript :: add decimal places to number javascript 
Javascript :: mui datatable onrowdelete 
Javascript :: scriptcase transforming local to global variable 
Javascript :: delete all items in an array 
Javascript :: Number o flines of typography element react material 
Javascript :: parcel react 
Javascript :: How to pass variables from one page to another with AngularJS 
Javascript :: angularjs How to get time difference from ZoneDateTime in javascript 
Javascript :: createaction ngrx example 
Javascript :: When doing a booking system, where would it be better to do? Back end or front end 
Javascript :: chain underscore 
Javascript :: How can I configure multiple sub domains in Express.js or Connect.js 
Javascript :: filter number from string in javascript 
Javascript :: react state based router 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =