当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Fabric.js fromHsla()用法及代码示例

fromHsla()方法用于为HSLA(色相饱和度和Alpha)格式的指定颜色返回新的颜色对象。

用法:

fromHsla(color)

参数:此方法接受如上所述和以下描述的参数:

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

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

范例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 fromHsla() function over 
   // the specified color value in HSLA format 
   console.log(fabric.Color 
      .fromHsla("hsla(0, 100%, 50%, 1.0)"));  
  </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 HSLA format 
   var Black = "hsla(0, 0% ,0%, 0.1)"; 
   var Red = "hsla(0, 100%, 50%, 1.0)"; 
  
   // Calling the fromHsla() function over 
   // the above specified color values 
   console.log(fabric.Color.fromHsla(Black));  
   console.log(fabric.Color.fromHsla(Red));  
  </script> 
</body> 
  
</html>

输出:

{"_source":[0,0,0,0.1]}
{"_source":[255,0,0,1]}

相关用法


注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 Fabric.js fromHsla() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。