Skip to content

Instantly share code, notes, and snippets.

View SamuelNunesDev's full-sized avatar
🧐
Looking for knowledge!

Samuel Nunes de Souza SamuelNunesDev

🧐
Looking for knowledge!
View GitHub Profile
@SamuelNunesDev
SamuelNunesDev / handleDarkenColor.js
Last active May 11, 2023 12:21
Darken a color in hex useful for dynamically creating a hover effect using only js. Ex: handleDarkenColor('#21FEEB') or handleDarkenColor('#ccc')
function handleDarkenColor(hex) {
let strHex = hex
if(![4, 7].includes(hex.length)) return '#171773'
else if(hex.length == 4) {
let newHex = '#'
hex.slice(1).split("").forEach((c) => {
newHex += c + c
})
strHex = newHex
}