Fabric.js easeOutCubic() 方法
在动画和游戏中,可以看到许多物体在画面中线性地从一个点移动到另一个点。但是使用缓动函数后,物体的进展方式可以采用不同的自然和有趣的形式。
缓动函数 是参数随时间变化的速率。它是那种在开始时缓慢移动并在结束时加速和减速的方程。这些方程式来自Robert Penner的书和网页。
easeOutCubic() 方法 用于立方缓动。
语法:
easeOutCubic(t, b, c, d)
参数: 此方法接受四个参数,如上所述并如下所述:
- t: 此参数保存动画开始的指定时间。例如,如果t的值为0,则表示动画刚开始。
- b: 此参数保存对象在x轴上的指定起始位置。例如,如果b的值为10,则表示对象在x坐标上的起始位置为10。
- c: 此参数保存对象值的指定变化量。例如,如果c的值为30,则表示对象必须向右移动30个单位,最后停在40。
- d: 此参数保存整个过程的指定持续时间。例如,如果d的值为2,则表示对象有2秒时间从10移动到40。
返回值: 此方法返回对象的缓动位置,即特定时间点上对象的位置。
示例1:
<!DOCTYPE html>
<html>
<head>
<!-- Adding the FabricJS library -->
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js">
</script>
</head>
<body>
<script type="text/javascript">
// Initializing easeOutCubic() function
function easeOutCubic (t, b, c, d) {
return c * ((t = t / d - 1) * t * t + 1) + b;
}
// Calling the easeOutCubic() function over
// the specified parameter values
console.log(fabric.util.ease.easeOutCubic(1, 2, 3, 4));
</script>
</body>
</html>
输出:
3.734375
示例2:
<!DOCTYPE html>
<html>
<head>
<!-- Adding the FabricJS library -->
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js">
</script>
</head>
<body>
<script type="text/javascript">
// Initializing easeOutCubic() function
function easeOutCubic (t, b, c, d) {
return c * ((t = t / d - 1) * t * t + 1) + b;
}
// Initializing the parameters with its values
var t = 5;
var b = 10;
var c = 40;
var d = 12;
// Calling the easeOutCubic() function over
// the specified parameter values
console.log(fabric.util.ease.easeOutCubic(t, b, c, d));
</script>
</body>
</html>
输出:
42.06018518518519