D3.js中的d3.interpolateHclLong()函數用於返回CIELChab兩種顏色之間的色彩空間插值器函數。它與interpolateHcl()函數幾乎相同,但是兩者之間的唯一區別是它不使用色調之間的最短路徑。
用法:
d3.interpolateHclLong(a, b);
參數:它采用以下兩個參數。
- a:這是顏色字符串。
- b:這是顏色字符串。它與第一種顏色的混合量由interpolateHclLong(0 <= x <= 1)確定
注意:如果x = 1大於b的一部分,則a的0部分返回顏色。更改x的值,並看到不同的顏色陰影。
返回值:下麵給出了上述函數的一些示例。
範例1:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width,
initial-scale=1.0">
<title>Document</title>
</head>
<style>
</style>
<body>
<!--fetching from CDN of D3.js -->
<script type = "text/javascript"
src = "https://d3js.org/d3.v4.min.js">
</script>
<script>
// Printing the return type of the function
console.log("function type is:",
typeof(d3.interpolateHclLong("blue", "white")))
// Using function d3.interpolateHclLong()
console.log("A RGB string:",
d3.interpolateHclLong("blue", "white")(0.5))
console.log("A RGB string",
d3.interpolateHclLong("blue", "white")(0.2))
</script>
</body>
</html>
輸出:
範例2:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width,
initial-scale=1.0">
<title>Document</title>
</head>
<style>
.box1, .box2{
display:flex;
margin-right:40px;
border-radius:20% 20%;
border:2px solid black;
width:150px;
height:150px;
}
div{
display:flex;
}
</style>
<body>
D3.interpolateHclLong()
<div>
<div class="box1">
</div>
<div class="box2">
</div>
</div>
<!--fetching from CDN of D3.js -->
<script type = "text/javascript"
src = "https://d3js.org/d3.v4.min.js">
</script>
<script>
let box1=document.querySelector(".box1");
let box2=document.querySelector(".box2");
let color=d3.interpolateHclLong("green", "white")(0.5);
let color2=d3.interpolateHclLong("green", "white")(0.2);
// Changing css of the div with class-name box1
box1.style.backgroundColor=color;
// Changing css of the div with class-name box2
box2.style.backgroundColor=color2;
</script>
</body>
</html>
輸出:
相關用法
- PHP Ds\Map get()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- p5.js box()用法及代碼示例
- PHP min( )用法及代碼示例
- d3.js d3.sum()用法及代碼示例
- PHP each()用法及代碼示例
- CSS url()用法及代碼示例
- PHP max( )用法及代碼示例
- PHP next()用法及代碼示例
- PHP key()用法及代碼示例
- d3.js d3.hsl()用法及代碼示例
- PHP pos()用法及代碼示例
- d3.js zip()用法及代碼示例
- PHP end()用法及代碼示例
- PHP Ds\Set xor()用法及代碼示例
注:本文由純淨天空篩選整理自tarun007大神的英文原創作品 D3.js interpolateHclLong() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。