Skip to content

Instantly share code, notes, and snippets.

@mtford90
Created May 1, 2016 15:14
Show Gist options
  • Save mtford90/d14e1cc9808e79817868ee0ae6f5d3cc to your computer and use it in GitHub Desktop.
Save mtford90/d14e1cc9808e79817868ee0ae6f5d3cc to your computer and use it in GitHub Desktop.
function rgba (hex, opacity) {
return `rgba(${hexToR(hex)}, ${hexToG(hex)}, ${hexToB(hex)}, ${opacity})`
}
function hexToR (h) {return parseInt((cutHex(h)).substring(0, 2), 16)}
function hexToG (h) {return parseInt((cutHex(h)).substring(2, 4), 16)}
function hexToB (h) {return parseInt((cutHex(h)).substring(4, 6), 16)}
function cutHex (h) {return (h.charAt(0) == "#") ? h.substring(1, 7) : h}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment