Fabric.js easeOutQuart()方法
在动画和游戏中,可以看到许多物体从一个点线性移动到另一个点。但是通过使用缓动函数,物体的进展方式可以变成不同的自然和有趣的形状。
缓动函数 是随时间变化的参数的变化率。它是一种在开始时缓慢移动,然后在结束时加速和减速的方程。这些方程组取自Robert Penner的书和网页。
方法 easeOutQuart() 用于四次缓动退出。
语法:
easeOutQuart(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 easeOutQuart() function
function easeOutQuart (t, b, c, d) {
return -c * ((t = t / d - 1) * t * t * t - 1) + b;
}
// Calling the easeOutQuart() function over
// the specified parameter values
console.log(fabric.util.ease.easeOutQuart(1, 2, 3, 4));
console.log(fabric.util.ease.easeOutQuart(1, 3, 5, 7));
console.log(fabric.util.ease.easeOutQuart(2, 4, 6, 8));
</script>
</body>
</html>
输出:
4.05078125
5.30112453144523
8.1015625
示例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 easeOutQuart() function
function easeOutQuart (t, b, c, d) {
return -c * ((t = t / d - 1) * t * t * t - 1) + b;
}
// Initializing the parameters with its values
var t1 = 5;
var b1 = 10;
var c1 = 40;
var d1 = 12;
var t2 = 2;
var b2 = 12;
var c2 = 10;
var d2 = 15;
// Calling the easeOutQuart() function over
// the specified parameter values
console.log(fabric.util.ease.easeOutQuart(t1, b1, c1, d1));
console.log(fabric.util.ease.easeOutQuart(t2, b2, c2, d2));
</script>
</body>
</html>
输出:
45.36844135802469
16.35832098765432
极客教程