如何增加视差运动的缓动



我正在对一些图像应用视差效果,我想对它们应用舒缓。视差的逻辑很简单,我在计算图像到窗口中心的距离,并将其表示为1的因子,其中0是屏幕中间,1是底部。我也可以把它应用到屏幕的上半部分,所以-1将是顶部。

理想情况下,我想直接从这里(http://gsgd.co.uk/sandbox/jquery/easing/jquery.easing.1.3.js)插入一些函数。所以假设我想使用' easeoutsin ':

// t: current time, b: begInnIng value, c: change In value, d: duration function (x, t, b, c, d) { return c * Math.sin(t/d * (Math.PI/2)) + b; }

我传递什么值?我认为最不明显的是d(持续时间),因为它们不是基于持续时间的动画。这些方程合适吗?

注意:我不想使用任何库,这是纯JS。

我自己想出来的。在不发布所有代码的情况下,这里是它的要点:

function easeInQuart(t, b, c, d) {
  return c*(t/=d)*t*t*t + b;
}
var deltaY // The distance the element is from the bottom of
           // the screen expressed as a factor of 1
var origY // The original position
var distanceY // The distance it can move
var y = easeInQuart(deltaY, origY, distanceY, 1); 

最新更新