gpt4 book ai didi

javascript - 在D3 V4中,如何正确使用 .ease ("bounce")?

转载 作者:行者123 更新时间:2023-11-28 03:56:05 25 4
gpt4 key购买 nike

这是我的代码:

<html>
<head>
<meta charset="UTF-8">
<title>circle</title>
</head>
 
<body>
<script src="http://d3js.org/d3.v4.min.js"></script>
    <script>
var width = 400;
var height = 400;
var svg = d3.select("body")
.append("svg")
.attr("width",width)
.attr("height",height);

var circle1 = svg.append("circle")
.attr("cx", 100)
.attr("cy", 100)
.attr("r", 45)
.style("fill","green");
circle1.transition()
.duration(1000) //延迟1000ms
.attr("cx", 300);

var circle2 = svg.append("circle")
.attr("cx", 100)
.attr("cy", 100)
.attr("r", 45)
.style("fill","green");

circle2.transition()
.duration(1500)
.attr("cx", 300)
.style("fill", "red");

var circle3 = svg.append("circle")
.attr("cx", 100)
.attr("cy", 100)
.attr("r", 45)
.style("fill","green");
circle3.transition()
.duration(2000)
.transition()
.ease("bounce")
.attr("cx", 300)
.style("fill", "red")
.attr("r", 25);

    </script>    
</body>
</html>

当我学习如何在 d3 v4.x 中使用 .ease("bounce") 时,错误总是在 html:45 中跳出。官方介绍中:.ease("bounce")现在应该这样使用:

d3.easeBounce(t)

但是也不起作用,所以我不知道如何修改它。能给我一个好的介绍吗?谢谢!

最佳答案

关于 transition.ease([value]) 的文档告诉我们,

The value must be specified as a function.

因此,只需传入缓动函数 d3.easeBounce而不实际调用它(注意,d3.easeBounce后面没有括号):

circle3.transition()
.duration(2000)
.transition()
.ease(d3.easeBounce) // Pass in the easing function

关于javascript - 在D3 V4中,如何正确使用 .ease ("bounce")?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47529685/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com