js invert color 1

js invert color

const invertColor = (bg) => {
	bg=parseInt(Number(bg.replace('#', '0x')), 10)
  bg=~bg
  bg=bg>>>0
  bg=bg&0x00ffffff
  bg='#' + bg.toString(16).padStart(6, "0")
  
  return bg
}

Here is what the above code is Doing:
1. It takes the hex value of the background color and converts it to a number.
2. It inverts the number.
3. It converts the inverted number back to a hex value.
4. It returns the hex value.

Similar Posts