Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript add alpha to hex

function addAlpha(color: string, opacity: number): string {
    // coerce values so ti is between 0 and 1.
    const _opacity = Math.round(Math.min(Math.max(opacity || 1, 0), 1) * 255);
    return color + _opacity.toString(16).toUpperCase();
}
addAlpha('FF0000', 1); // returns 'FF0000FF'
addAlpha('FF0000', 0.5); // returns 'FF000080'
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to connect mongoose database with nodejs 
Javascript :: ascii to hex js 
Javascript :: js distance from top 
Javascript :: how to remove element from array react native 
Javascript :: react index.js BrowserRouter 
Javascript :: get the middle character js 
Javascript :: how to make 1st letter capital in ejs 
Javascript :: javascript test if element has focus 
Javascript :: check if character is a letter 
Javascript :: getelementbytagname js 
Javascript :: angular copy 
Javascript :: settings icon in react fontawesome 
Javascript :: can immigrants vote in uk 
Javascript :: gmail regex 
Javascript :: Convert underscore strings to camel Case 
Javascript :: express serve static files 
Javascript :: react native text area align top 
Javascript :: onchange text input react native 
Javascript :: vanilla tilt.js 
Javascript :: Discord.client once 
Javascript :: jquery all elements whose id contains 
Javascript :: add favicon to next js static site 
Javascript :: timer in javascript 
Javascript :: java script cosinus grad 
Javascript :: Chart is not a constructor 
Javascript :: javascript is variable a string 
Javascript :: express messages 
Javascript :: form confirm before submit 
Javascript :: v-switch vuex store 
Javascript :: chrome extension communication between popup and content script 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =