Fabric.js fromHsl() 方法
fromHsl() 方法用于返回指定颜色的新颜色对象,以HSL(色调-饱和度-亮度)格式表示。
语法:
fromHsl(color)
参数:
此方法接受一个参数,如上所述,并在下面进行描述:
- color:
此参数保存以HSL格式指定的字符串颜色值。
返回值:
此方法返回以“RGBA(红-绿-蓝-透明度)”格式表示的指定HSL格式颜色的新颜色对象。
示例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 fromHsl() function over
// the specified color value in HSL format
console.log(fabric.Color.fromHsl("hsl(0, 100%, 50%)"));
</script>
</body>
</html>
输出:
{"_source":[255,0,0,1]}
示例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 HSL format
var Green = "hsl(120, 100%, 50%)";
var Blue = "hsl(240, 100%, 50%)";
// Calling the fromHsl() function over
// the above specified color values
console.log(fabric.Color.fromHsl(Green));
console.log(fabric.Color.fromHsl(Blue));
</script>
</body>
</html>
输出:
{"_source":[0,255,0,1]}
{"_source":[0,0,255,1]}