Fabric.js toHsla()方法
toHsla()方法 用于将指定颜色表示的任何类型转换为其HSLA(色调,饱和度,亮度和透明度)表示。
语法:
toHsla()
参数: 此方法不接受任何参数。
返回值: 此方法以HSLA格式返回颜色表示。
示例1:
<!DOCTYPE html>
<html>
<head>
<!-- Adding the FabricJS library -->
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js">
</script>
</head>
<body>
<script type="text/javascript">
// Calling the toHsla() function over
// the specified color values
console.log(new fabric.Color("rgb(10, 120, 150)").toHsla());
console.log(new fabric.Color("rgba(100, 20, 255, 0.3)").toHsla());
</script>
</body>
</html>
输出:
hsla(193,88%,31%,1)
hsla(260,100%,54%,0.3)
示例2:
<!DOCTYPE html>
<html>
<head>
<!-- Adding the FabricJS library -->
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js">
</script>
</head>
<body>
<script type="text/javascript">
// Initializing some color values in different color format
var A = "rgb(0, 12, 50)";
var B = "rgba(10, 13, 250, 0.1)";
var C = "hex(ffffff)";
// Calling the toHsla() function over
// the above specified color values
console.log(new fabric.Color(A).toHsla());
console.log(new fabric.Color(B).toHsla());
console.log(new fabric.Color(C).toHsla());
</script>
</body>
</html>
输出:
hsla(226,100%,10%,1)
hsla(239,96%,51%,0.1)
hsla(0,0%,0%,1)