Fabric.js easeOutBack() 方法
在动画和游戏中,可以看到许多物体在不同点之间以线性方式移动。但是在使用缓动函数之后,物体的进展方式可以采取不同的自然而有趣的形状。
缓动函数 是参数随时间变化的速率。它是一种在开始时缓慢移动、加速并在结束时减速的方程组。这些方程组来自 Robert Penner 的书和网页。
easeOutBack() 方法 用于向后缓动。
语法:
easeOutBack(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 easeOutBack() function
function easeOutBack (t, b, c, d) {
if (s == undefined) s = 1.70158;
return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
}
// Calling the easeOutBack() function over
// the specified parameter values
console.log(fabric.util.ease.easeOutBack(1, 2, 3, 4));
</script>
</body>
</html>
输出:
4.452229062500001
示例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 easeOutBack() function
function easeOutBack (t, b, c, d) {
if (s == undefined) s = 1.70158;
return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
}
// Initializing the parameters with its values
var t = 5;
var b = 10;
var c = 40;
var d = 12;
// Calling the easeOutBack() function over
// the specified parameter values
console.log(fabric.util.ease.easeOutBack(t, b, c, d));
</script>
</body>
</html>
输出:
51.71034953703704