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]}
相關用法
- Lodash _.method()用法及代碼示例
- Node.js Http2ServerRequest.method用法及代碼示例
- Node.js http.IncomingMessage.method用法及代碼示例
- Javascript dataView.getInt16()用法及代碼示例
- Javascript RegExp toString()用法及代碼示例
- Node.js URLSearchParams.has()用法及代碼示例
- JavaScript Math cosh()用法及代碼示例
- HTML DOM isEqualNode()用法及代碼示例
- JavaScript Date toLocaleTimeString()用法及代碼示例
- Node.js crypto.createHash()用法及代碼示例
- Node.js writeStream.clearLine()用法及代碼示例
- Node.js fs.link()用法及代碼示例
- JavaScript Math random()用法及代碼示例
- JavaScript Math round()用法及代碼示例
- Javascript toString()用法及代碼示例
- Javascript Number.isInteger( )用法及代碼示例
- Javascript Number.isFinite()用法及代碼示例
- Javascript toFixed()用法及代碼示例
- Javascript toPrecision()用法及代碼示例
- JavaScript Math abs()用法及代碼示例
- JavaScript Math sqrt()用法及代碼示例
- JavaScript Math floor()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Fabric.js fromHsla() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。