我使用的d3版本3和我试图使用d3的易感功能的动画。根据函数的定义,它有一个返回值
function ease(type: 'cubic-in'): (t: number) => number;
我期望一个数字作为返回值在我的计算中使用它。但是,现在我如何将ease函数的返回值转换为一个数字。还有其他方法可以做到这一点吗?
谢谢。
发布于 2017-07-28 01:22:29
d3.ease
已经返回一个数字。
你只需要把你想要的值传递给d3.ease
d3.ease(type)(value);
下面是一个关于"cubic-in"
的演示,如您的问题所示:
function ease(value) {
return d3.ease("cubic-in")(value);
}
console.log("ease for 0.1: " + ease(4));
console.log("ease for 0.5: " + ease(0.5));
console.log("ease for 0.8: " + ease(0.8));
console.log("ease for 0.95: " + ease(0.95));
<script src="https://d3js.org/d3.v3.min.js"></script>
请记住,传递的值和返回的值在0
和1
之间。根据API接口
放松函数在域
t
中获取当前参数化的时间值[0,1]
,并将其映射到类似范围内的另一个值。
https://stackoverflow.com/questions/45357148
复制相似问题