d3.InterpolateRgbBasis()函數用於返回給定的顏色數組的統一非有理B-spline插值器函數,該數組將轉換為RGB顏色。
用法:
d3.interpolateRgbBasis(colors);
參數:它需要多種顏色。
返回:它返回插值器函數。
下麵給出了一些Interpolate.RgbBasis()函數的示例。
範例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>
.b1, .b2{
width:100px;
height:100px;
}
</style>
<body>
<div class="b1">
</div>
<div class="b2">
</div>
<!--Fetching from CDN of D3.js -->
<script type = "text/javascript"
src =
"https://d3js.org/d3.v4.min.js">
</script>
<script>
console.log("Type of the function is:",
typeof(d3.interpolateRgbBasis(["red", "white", "blue"])))
console.log(
d3.interpolateRgbBasis(["red", "white", "blue"])(0.5))
console.log(
d3.interpolateRgbBasis(["red", "white", "blue"])(0.2))
</script>
</body>
</html>
輸出:
範例2:在HTML中使用d3.interpolateRgbBasis。
<!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>
div{
width:100px;
height:100px;
}
</style>
<body>
D3.interpolateRgbBasis()
<div class="b1">
</div>
<div class="b2">
</div>
<!--Fetching from CDN of D3.js -->
<script type = "text/javascript"
src =
"https://d3js.org/d3.v4.min.js">
</script>
<script>
// Array of colors is given
let color=
d3.interpolateRgbBasis([ "white", "red", "green"])(0.9);
let color2=
d3.interpolateRgbBasis(["red", "white", "green"])(0.8);
let b1=document.querySelector(".b1");
let b2=document.querySelector(".b2");
b1.style.backgroundColor=color;
b2.style.backgroundColor=color2;
</script>
</body>
</html>
輸出:
相關用法
- CSS var()用法及代碼示例
- d3.js d3.hsl()用法及代碼示例
- p5.js nfs()用法及代碼示例
- p5.js nf()用法及代碼示例
- PHP end()用法及代碼示例
- PHP each()用法及代碼示例
- p5.js nfc()用法及代碼示例
- p5.js nfp()用法及代碼示例
- d3.js zip()用法及代碼示例
- PHP key()用法及代碼示例
- PHP pos()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- p5.js box()用法及代碼示例
- d3.js d3.min()用法及代碼示例
- PHP max( )用法及代碼示例
注:本文由純淨天空篩選整理自tarun007大神的英文原創作品 D3.js interpolateRgbBasis() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。