Fabric.js easeInQuint() 方法
在游戏或动画中,有许多移动的物体可以以线性方式从A点移动到B点,但应用缓动函数可以使其看起来更加自然。缓动函数告诉动画如何进行进度。这样,直线运动可以变得有趣。
缓动函数 指定参数随时间的变化率。它的方程能够使物体在起点慢速移动,然后加速或放慢接近终点。最常见的缓动方程来自Robert Penner的书籍和网页。
easeInQuint() 方法 用于五次方缓动。
语法:
easeInQuint(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 easeInQuint() function
function easeInQuint (t, b, c, d) {
return c * (t /= d) * t * t * t * t + b;
}
// Calling the easeInQuint() function over
// the specified parameter values
console.log(fabric.util.ease.easeInQuint(1, 2, 3, 4));
</script>
</body>
</html>
输出:
2.0029296875
示例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 easeInQuint() function
function easeInQuint (t, b, c, d) {
return c * (t /= d) * t * t * t * t + b;
}
// Initializing the parameters with its values
var t = 5;
var b = 10;
var c = 40;
var d = 12;
// Calling the easeInQuint() function over
// the specified parameter values
console.log(fabric.util.ease.easeInQuint(t, b, c, d));
</script>
</body>
</html>
输出:
10.502346965020577