當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Fabric.js getSource()用法及代碼示例

getSource()方法用於獲取指定顏色值的來源。

用法:

getSource()

參數:此方法不接受任何參數。

返回值:此方法返回指定顏色值的來源。返回的源值將以數組表示形式。

範例1:



HTML

<!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 getSource() function over 
 // the specified color values 
 console.log(new fabric.Color("hsl(0, 100%, 50%)").getSource()); 
 console.log(new fabric.Color("hsla(10%, 100%, 50%, 0.2)").getSource()); 
</script> 
  
</body> 
  
</html>

輸出:

[255,0,0,1]
[0,0,0,1]

範例2:

HTML

<!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 = "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 getSource() function over 
 // the above specified color values 
 console.log(new fabric.Color(A).getSource()); 
 console.log(new fabric.Color(B).getSource()); 
 console.log(new fabric.Color(C).getSource()); 
 console.log(new fabric.Color(D).getSource()); 
 console.log(new fabric.Color(E).getSource()); 
</script> 
  
</body> 
  
</html>

輸出:

[0,0,0,1]
[72,59,55,1]
[46,24,20,0.6]
[10,40,13,1]
[10,40,13,0.9]

相關用法


注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Fabric.js getSource() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。