Famo.us: get the new position of a draggable Surface

…衆ロ難τιáo~ 提交于 2020-01-03 00:53:12

问题


After using drag and drop on a surface I want to get the exact new position of this Surface. How can I do that?


回答1:


You will be able to get the position from your Draggable modifier on end event draggable.on('end',function(e){var pos = e.position;})

Here is a link for the following code example:

var mainContext = Engine.createContext();

var transTransform = new TransitionableTransform();
transTransform.set(Transform.translate(100, 0, 0));

var surface = new Surface({
    size: [300, 100],
    properties: {
        backgroundColor: 'rgba(255,0,0,0.1)',
        cursor: 'pointer'
    }
});

var dragSurface = new Surface({
    content: 'Drag Me',
    size: [100, 100],
    properties: {
        backgroundColor: 'rgba(0,0,0,0.1)',
        cursor: 'pointer'
    }
});

var modifier = new Modifier({
    origin: [0, 0],
    align: [0, 0],
    transform: transTransform
});

var draggable = new Draggable();

draggable.subscribe(dragSurface);

var content = 'Not Draggable';
surface.setContent(content);

mainContext.add(modifier).add(surface);
mainContext.add(draggable).add(dragSurface);

draggable.on('update', function (e) {
    var pos = e.position;
    surface.setContent('Draggable Position is '+pos);
    transTransform.set(Transform.translate(pos[0]+100, pos[1], 0));
})

draggable.on('end', function (e) {
    var pos = e.position;
    surface.setContent('Draggable End Position is '+pos);
    transTransform.set(Transform.translate(pos[0]+100, pos[1], 0));
})

Note: Modifier.setTransform() has been deprecated.



来源:https://stackoverflow.com/questions/26193020/famo-us-get-the-new-position-of-a-draggable-surface

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!