toHex()方法用於將任何類型的指定顏色表示形式轉換為它的HEX(十六進製)表示形式。
用法:
toHex()
參數:此方法不接受任何參數。
返回值:此方法以十六進製格式返回顏色表示。
範例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 toHex() function over
// the specified rgb and rgba color format
console.log(new fabric.Color('rgb(10, 20, 30)').toHex());
console.log(new fabric.Color('rgba(22, 255, 120, 0.9)').toHex());
</script>
</body>
</html>
輸出:
0A141E 16FF78
範例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 = "rgb(0, 12, 50)";
var B = "rgba(10, 13, 250, 0.1)";
var C = "hsl(0, 100%, 50%)";
var D = "hsla(10%, 0, 0, 0.2)";
// Calling the toHex() function over
// the above specified color values
console.log(new fabric.Color(A).toHex());
console.log(new fabric.Color(B).toHex());
console.log(new fabric.Color(C).toHex());
console.log(new fabric.Color(D).toHex());
</script>
</body>
</html>
輸出:
000C32 0A0DFA FF0000 000000
相關用法
- 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 toHex() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。