d3.js中的d3.easeLinear()函數用於線性緩和到特定元素的過渡效果。該線性緩動函數返回一個恒等函數。
用法:
d3.easeLinear
參數:該函數不接受任何參數。
返回值:此函數不返回任何值。
方法:
D3.js過渡函數將用於對特定元素應用不同的緩動效果。首先,創建一個SVG元素並將其附加到HTML頁麵的主體,然後創建一個圓並將其附加到SVG。設置圓的一些屬性以使其具有漂亮的顏色和大小,並應用d3.transition函數,然後再應用ease()函數,並以d3.easeLinear作為參數來簡化函數。
下麵給出的是上麵給出的函數的一些例子。
範例1:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width,
initial-scale=1.0">
<script src="https://d3js.org/d3.v4.min.js"></script>
</head>
<body>
<h3 style="color:green">GeeksforGeeks</h3>
<svg width="500px" height="500px">
</svg>
<script>
var svg = d3.select("svg");
svg.append("circle")
.attr("r", 30)
.attr("cy",40)
.attr("cx",30)
.attr("fill", "green")
.transition()
// Use of easeLinear
.ease(d3.easeLinear)
.duration(2000)
.attr("cy",40)
.attr("cx",200);
</script>
</body>
</html>
輸出:
範例2:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width,
initial-scale=1.0">
<script src="https://d3js.org/d3.v4.min.js"></script>
</head>
<body>
<h1 style="color:green">GeeksforGeeks</h1>
<svg width="500px" height="500px">
</svg>
<script>
var svg = d3.select("svg")
.attr("transform","translate(0,-50)");
svg.append("rect")
.attr("x", 10)
.attr("y",50)
.attr("width",150)
.attr("height",50)
.attr("fill", "green")
.transition()
// Ease linear
.ease(d3.easeLinear)
.attr("x", 100)
.attr("y",100)
.attr("width",100)
.attr("height",10)
.duration(2000);
</script>
</body>
</html>
輸出:
相關用法
- PHP imagecreatetruecolor()用法及代碼示例
- p5.js year()用法及代碼示例
- d3.js d3.utcTuesdays()用法及代碼示例
- PHP ImagickDraw getTextAlignment()用法及代碼示例
- PHP Ds\Sequence last()用法及代碼示例
- PHP array_udiff_uassoc()用法及代碼示例
- PHP geoip_continent_code_by_name()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- PHP GmagickPixel setcolor()用法及代碼示例
- PHP opendir()用法及代碼示例
- PHP cal_to_jd()用法及代碼示例
- d3.js d3.bisectLeft()用法及代碼示例
- PHP stream_get_transports()用法及代碼示例
- PHP Ds\Deque pop()用法及代碼示例
注:本文由純淨天空篩選整理自tarun007大神的英文原創作品 D3.js easeLinear() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。