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


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


在游戏或动画中,有许多移动的对象可以将它们以线性方式从A点移动到B点,但是在应用缓动或缓动函数后,它可以使其看起来更自然。缓动函数表示如何进行动画播放。这样,直线运动可以呈现出有趣的形状。

缓动函数指定参数随时间的变化率。它的方程使事物在开始时缓慢移动并加速,或在结束时减速。最常见的缓解方程组来自罗伯特·彭纳(Robert Penner)的书和网页。

easeInOutExpo()方法用于进行 index 缓和。

用法:

easeInOutExpo(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

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

输出:

2.046875

范例2:

HTML

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

输出:

16.299605249474368




相关用法


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