Fabric.js fromHsl() 方法


Fabric.js fromHsl() 方法

fromHsl() 方法用于以 HSL(Hue-Saturation-Lightness) 格式返回指定颜色的新颜色对象。

句法:

fromHsl(color)

参数:此方法接受上面提到的参数,如下所述:

  • color:此参数以 HSL 格式保存指定的字符串颜色值。

返回值:该方法以“RGBA(Red-Green-Blue-Alpha)”格式为HSL格式的指定颜色返回一个新的颜色对象。

示例 1:

Javascript
<!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>


Javascript
<!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":[255,0,0,1]}

示例 2:

Javascript

<!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]}


Made with ❤️ in Chengdu. Copyright reserved 2019-2022.

蜀ICP备20006366号-1