Famo.us:获取可拖动曲面的新位置 [英] Famo.us: get the new position of a draggable Surface

查看:142
本文介绍了Famo.us:获取可拖动曲面的新位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

您将能够从您的Draggable修饰符得到结束事件 draggable.on('end',function(e){var pos = e.position;})

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));
})

Modifier.setTransform() 已被弃用。

Note: Modifier.setTransform() has been deprecated.

这篇关于Famo.us:获取可拖动曲面的新位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆