D3.js中的d3.image()函數是請求API的一部分,用於從任何給定的圖像URL中獲取圖像。如果在函數中也指定了init,則它將在加載圖像之前在圖像上設置任何其他屬性。
用法:
d3.image(input[, init]);
參數:該函數接受如上所述和以下描述的單個參數:
- input:它獲取要獲取的圖像的地址。
返回值:它從圖像URL返回圖像。
以下示例說明了JavaScript中的D3.js image()函數。
範例1:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
path1tent="width=device-width,
initial-scale=1.0"/>
<title>D3.js image() Function</title>
</head>
<style></style>
<body>
<script src=
"https://d3js.org/d3.v4.min.js">
</script>
<script src=
"https://d3js.org/d3-dsv.v1.min.js">
</script>
<script src=
"https://d3js.org/d3-fetch.v1.min.js">
</script>
<script>
d3.image("https://robohash.org/image",
{ crossOrigin:"anonymous" }).then((img) => {
console.log(img);
});
</script>
</body>
</html>
輸出:
範例2:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
path1tent="width=device-width,
initial-scale=1.0"/>
<title>D3.js image() Function</title>
</head>
<style></style>
<body>
<script src=
"https://d3js.org/d3.v4.min.js">
</script>
<script src=
"https://d3js.org/d3-dsv.v1.min.js">
</script>
<script src=
"https://d3js.org/d3-fetch.v1.min.js">
</script>
<script>
d3.image(
`https://pbs.twimg.com/profile_images/1138375574726955008/1fNUyEdv_400x400.png`,
{ crossOrigin:"anonymous" }).then((img) => {
document.body.append("Image using d3.image()");
document.body.append(img);
});
</script>
</body>
</html>
輸出:
相關用法
注:本文由純淨天空篩選整理自tarun007大神的英文原創作品 D3.js image() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。