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


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

overlayWith()方法用於使用給定的顏色作為參數覆蓋給定的顏色。

用法:

overlayWith(otherColor)

參數:此方法接受如上所述和以下描述的參數:

  • otherColor:此參數保留指定的顏色。

返回值:此方法返回覆蓋的顏色。

範例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 overlayWith() function over 
 // the specified color values 
 console.log(new fabric.Color("rgb(10, 40, 13)").overlayWith("rgb(10, 41, 13, 1)")); 
</script> 
  
</body> 
  
</html>

輸出:

{"_source":[10,41,13,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)"; 
  
 // Calling the overlayWith() function over 
 // the above specified color values 
 console.log(new fabric.Color(A).overlayWith("rgb(10, 41, 13, 1)")); 
 console.log(new fabric.Color(A).overlayWith("rgba(1, 4, 3, 0.2)")); 
 console.log(new fabric.Color(A).overlayWith("hex(ffffff)")); 
</script> 
  
</body> 
  
</html>

輸出:

{"_source":[5,21,7,1]}
{"_source":[1,2,2,1]}
{"_source":[0,0,0,1]}

相關用法


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