Fabric.js easeInSine()方法
在游戏或动画中,有许多移动的物体可以使它们从点A线性移动到点B,但是通过应用缓动函数,可以使其看起来更自然。缓动函数描述了动画如何进行。通过这种方式,直线运动可以呈现出有趣的形状。
缓动函数 指定了一个参数随时间变化的速率。它的方程可以使物体在开始时减速、在末尾时加速或减速。最常见的缓动函数集合来自罗伯特·佩纳的书籍和网站。
easeInSine() 方法 用于在所使用的对象上产生圆弧正弦效果。
语法:
easeInSine(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:
<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">
// The easeInSine() function
function easeInSine (t, b, c, d) {
return -c * Math.cos(
t / d * (Math.PI / 2)) +
c + b;
}
// Calling the easeInSine() function
// over the specified parameter values
console.log(
fabric.util.ease.easeInSine(1, 2, 3, 4)
);
</script>
</body>
</html>
输出:
2.22836140246614
示例2:
<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 the parameters with its values
var t = 5;
var b = 10;
var c = 40;
var d = 12;
// Calling the easeInSine() function
// over the specified parameter values
console.log(
fabric.util.ease.easeInSine(t, b, c, d)
);
</script>
</body>
</html>
输出:
18.265866388350595
极客教程