joint.js触发新克隆元素的拖动开始

时间:2014-01-06 13:30:00

标签: jquery jointjs

如何在关节js中的克隆关节元素上触发pointerdown / dragstart? 在工具箱文件上触发toolBoxPointerDown事件时会触发pointerdown。 在addNode上触发pointerup事件时会触发_this.paperDrag

var toolBoxPointerDown = function(cell, event) {
        _this.action = 'addNode';
        $(document.body).append(_this.paperDrag.$el); 
        _this.clone = cell.model.clone(), _this.cloneBbox = cell.getBBox();

        _this.clone.set("position", {
            x: cell.model.attributes.position.x,
            y: cell.model.attributes.position.y 
        }), _this.paperDrag.addCell(_this.clone), _this.paperDrag.setDimensions("100%", "100%");

        _this.paperDrag.$el.offset({
            left: 0,
            top: 0
        });

        _this.paperDrag.findViewByModel(_this.clone.id).pointerdown();
    }

    var addNode = function(node, position) {
        var celltoAdd = _this.clone.clone();
        celltoAdd.set('position', { x: _this.clone.get('position').x - $('.toolbox').width(), y: _this.clone.get('position').y });


        if(celltoAdd.attributes.position.x > - 50){
            renderNode(celltoAdd.attributes);
        }
         _this.paperDrag.$el.detach();
        _this.clone.remove();
        _this.action = 'nodeAdded';
    }

1 个答案:

答案 0 :(得分:0)

将此代码添加到您的纸张制作工具中:

_this.paperDrag.on('element:pointerup', this.addNode , this);
_this.paperDrag.on('element:pointerdown', this.toolBoxPointerDown , this);

一些解释:joint.dia.ElementView内置了指针和指针,这两个函数的最后一个代码行如下所示进行通知:

this.notify('element:pointerdown', evt, x, y);

并且您的paper.on('element:pointerdown')已在该通知产生后执行。

相关问题