The getAlpha() method is used to get the value of alpha channel for the specified color value.
Syntax:
getAlpha()
Parameters: This method does not accept any parameters.
Return Value: This method returns the alpha channel value.
Example 1:
Javascript
<!DOCTYPE html> <html> <head> <!-- Adding the FabricJS library -->
<script src=
</script>
</head> <body> <script type= "text/javascript" >
// Calling the getAlpha() function over
// the specified color values
console.log( new fabric.Color( "hsl(0, 100%, 50%)" ).getAlpha());
console.log( new fabric.Color( "hsla(0, 100%, 50%, 0.2)" ).getAlpha());
</script> </body> </html> |
Output:
1 0.2
Example 2:
Javascript
<!DOCTYPE html> <html> <head> <!-- Adding the FabricJS library -->
<script src=
</script>
</head> <body> <script type= "text/javascript" >
// Initializing some color values in different color format
var A = "hex(fff00f)" ;
var B = "hsl(12, 13%, 25%)" ;
var C = "hsla(10, 40%, 13%, 0.6)" ;
var D = "rgb(10, 40, 13)" ;
var E = "rgba(10, 40, 13, 0.9)" ;
// Calling the getAlpha() function over
// the above specified color values
console.log( new fabric.Color(A).getAlpha());
console.log( new fabric.Color(B).getAlpha());
console.log( new fabric.Color(C).getAlpha());
console.log( new fabric.Color(D).getAlpha());
console.log( new fabric.Color(E).getAlpha());
</script> </body> </html> |
Output:
1 1 0.6 1 0.9