从Draggable获取表面

时间:2014-05-16 20:21:49

标签: javascript famo.us

请大家帮助我。我有这段代码:

var image = new ImageSurface({
    size: [300, 300],
    properties: {
        border: '4px solid white'
    }
});

image.setContent('/img/' + _.random(1,7) + '.jpg');

var draggable = new Draggable({scale: 1});
image.pipe(draggable);

draggable.on('end', function(e) {
    // SURFACE????
});

var stateModifier = new StateModifier();

node.add(stateModifier).add(draggable).add(image);

stateModifier.setTransform(
    Transform.translate(100, 10, 0),
    { duration : 1000, curve: Easing.outElastic }
);

如何从可拖动事件中获取Surface对象?事件中的参数只是位置。

1 个答案:

答案 0 :(得分:0)

首先,我想知道为什么你需要从事件中获得表面。如果每个表面有一个可拖动的,那么你可以用简单的数据绑定做一些事情。

例如..

var draggable = new Draggable({scale: 1});

draggable.image = image;

draggable.on('end', function(e) {
    var image = this.image;
});

如果您真的需要从事件中获得表面,则必须编辑发出事件的代码。

仅适用于结束活动..

从Draggable.js第129行开始

function _handleEnd() {
    if (!this._active) return;
    this.eventOutput.emit('end', {position : this.getPosition()});
}

可以更改为..

function _handleEnd() {
    if (!this._active) return;
    this.eventOutput.emit('end', {position : this.getPosition(), originalEvent:event });
}

现在你可以做..

var draggable = new Draggable({scale: 1});

draggable.on('end', function(e) {
    var image = e.originalEvent.origin;
});

祝你好运!

相关问题