Fabric.js easeInCirc()方法
在游戏或动画中,有许多移动的对象可以以线性方式从点A移动到点B,但是在应用缓动或缓动函数之后,可以使其看起来更自然。缓动函数定义了动画的进展方式。这样,直线运动可以呈现出有趣的形状。
缓动函数 指定了参数随时间变化的速率。它的方程使得某物在开始时移动缓慢,然后在接近结束时加速或减速。请参考Robert Penner的书籍和网页了解关于缓动函数的更多信息。
easeInCirc() 方法 用于圆形缓动。
语法:
easeInCirc(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:
Index.js
<!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 easeInCirc() function
function easeInCirc (t, b, c, d) {
return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
}
// Calling the easeInCirc() function over
// the specified parameter values
console.log(fabric.util.ease.easeInCirc(1, 2, 3, 4));
</script>
</body>
</html>
输出:
2.095262490344437
示例2:
Index.js
<!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 easeInCirc() function
function easeInCirc (t, b, c, d) {
return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
}
// Initializing the parameters with its values
var t = 5;
var b = 10;
var c = 40;
var d = 12;
// Calling the easeInCirc() function over
// the specified parameter values
console.log(fabric.util.ease.easeInCirc(t, b, c, d));
</script>
</body>
</html>
输出:
13.637626284547618