3

我使用 fa-draggable 有效的指令:

<fa-modifier fa-size="[90, 90]">
             <fa-draggable fa-pipe-from="item.handler"
                           fa-options="draggableOptions"
                           fa-pipe-to="item.handler">
                           <fa-surface fa-background-color="'#268bd2'"
                                       fa-pipe-to="item.handler">
                                        A
                           </fa-surface>
             </fa-draggable>
</fa-modifier>

在我的控制器内部我设置:

$scope.draggableOptions = {
        xRange: [-4, 4],
        yRange: [-4, 4]
    };
$scope.item.handler = new EventHandler();
$scope.item.handler.on('end', function (e) {
                //return somehow to default position
            });

如何确保在拖动事件完成后,可拖动表面返回到默认位置?

我发现了这个问题Drag a Famous surface and have it transition back to origin on mouseup? 但我不知道如何在我的情况下使用“setPosition”功能?

4

2 回答 2

2

你可以设置位置

$famous.find('fa-draggable')[0].modifier.setPosition([4,4])

演示 Plunker:http ://plnkr.co/edit/ZwLFXsjoxHyXqPpUgxJh?p=preview

于 2015-07-28T13:10:49.903 回答
0

上次我使用 Famous/Angular 时,我遇到了类似的问题,最终没有使用可拖动表面。
如果您查看文档,则并不是很有用。
顺便说一句,你可以试试这个:

<fa-modifier fa-size="[90, 90]" fa-translate="item.position.get()">
             <fa-draggable fa-pipe-from="item.handler"
                           fa-options="draggableOptions"
                           fa-pipe-to="item.handler">
                           <fa-surface fa-background-color="'#268bd2'"
                                       fa-pipe-to="item.handler">
                                        A
                           </fa-surface>
             </fa-draggable>
</fa-modifier>

在你的控制器中

var _initialState = [0, 0, 0]; //This should be your initial state

$scope.item.position = new Transitionable(_initialState); // This define item.position as a Transitionable object
$scope.item.handler.on('end', function (e) {
   $scope.item.position.set(_initialState);
});

我从来没有尝试过这个,我现在没有时间去做,但我希望这个建议可以帮助你。

更新

这是使用可拖动指令的视图示例
看起来它正在做类似于我提议的事情。

于 2015-07-28T11:57:35.343 回答