当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Fabric.js easeOutExpo()用法及代码示例


在动画和游戏中,可以看到许多对象从一个点线性地移动到另一点。但是在使用“缓动”函数后,对象的前进方式可以采用其他自然有趣的形状。

缓动函数是参数随时间变化的速率。正是这种方程式在开始时缓慢移动并加速,而在结束时缓慢移动。这些方程式取自Robert Penner的书和网页。

easeOutExpo()方法用于 index 缓和。

用法:

easeOutExpo(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:

Javascript

<!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 easeOutExpo() function 
 function easeOutExpo (t, b, c, d) { 
    return (t == d) ? b + c:c * (-Math.pow(2, -10 * t / d) + 1) + b; 
 } 
   
 // Calling the easeOutExpo() function over 
 // the specified parameter values 
 console.log(fabric.util.ease.easeOutExpo(1, 2, 3, 4));  
</script> 
  
</body> 
  
</html>

输出:

4.4696699141100895

范例2:

Javascript

<!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 easeOutExpo() function 
 function easeOutExpo (t, b, c, d) { 
    return (t == d) ? b + c:c * (-Math.pow(2, -10 * t / d) + 1) + b; 
 } 
   
 // Initializing the parameters with its values 
 var t = 5; 
 var b = 10; 
 var c = 40; 
 var d = 12; 
  
 // Calling the easeOutExpo() function over 
 // the specified parameter values 
 console.log(fabric.util.ease.easeOutExpo(t, b, c, d));  
</script> 
  
</body> 
  
</html>

输出:

47.772753204649156

相关用法


注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 Fabric.js easeOutExpo() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。