Famo.us:获得可拖动Surface的新位置

时间:2014-10-04 12:53:04

标签: drag-and-drop famo.us

在表面上使用拖放后,我想获得此Surface的确切新位置。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:2)

您可以从Draggable修饰符on end事件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));
})

注意:Modifier.setTransform() 已被弃用。