Famo.us:如何以编程方式对滚动视图的位置进行动画处理

Famo.us: How can I programmatically animate the position of a Scrollview?

本文关键字:位置 视图 处理 动画 滚动 us 方式 编程 Famo      更新时间:2023-09-26

我可以直接用myScrollview.setPosition(y)设置位置,也可以用myScrollview.setVelocity(delta)手动应用动作。但是,有没有办法将平滑、精确的缓动过渡应用于滚动视图的位置?谢谢!

或者,

您可以使用 FlexScrollView,它使用物理弹簧将滚动位置平滑地拉到新位置。它还具有用于设置滚动位置的扩展API:

https://github.com/IjzerenHein/famous-flex/blob/master/docs/FlexScrollView.mdhttps://github.com/IjzerenHein/famous-flex/blob/master/docs/ScrollController.mdhttps://github.com/IjzerenHein/famous-flex/blob/master/tutorials/FlexScrollView.mdhttps://github.com/IjzerenHein/famous-flex

这是我确定的(可能有更好的方法可以做到这一点):

var self = this; // current view object
var transitionTime = 500; //ms
// How far do we need to move every 16.67 ms (1/60th of a second)?
self.animatedScrollDelta = (self.myScrollview.getPosition() / (transitionTime / 16.6667));
self.animatedScroller = Timer.every(animateScrollerCallback, 1);
function animateScrollerCallback()
{
    var pos = self.myScrollview.getPosition() - self.animatedScrollDelta;
    self.myScrollview.setPosition(Math.max(0, pos));
    if(pos < 0)
        Timer.clear(self.animatedScroller);     
}

注意:这是线性动画,这正是我所需要的。我相信其他缓动公式可以使用补间过渡来实现。