【问题标题】:Raphael drag clone onDragOver拉斐尔拖动克隆onDragOver
【发布时间】:2015-04-03 18:02:04
【问题描述】:

目前我通过在dragStart 函数中使用element.clone() 并在dragMove 函数中移动克隆(在dragStop 函数中删除它)来拖动可拖动Raphael 元素的克隆。

这会导致可拖动元素的 onDragOver 函数出现问题,因为大多数情况下,克隆会引发相应的事件而不是目标事件。

一些代码:

dragStart = function() {
    var s = this, c = s.clone();
    s.data('clone', c);
    c.ox = c.attr('cx'); 
    c.oy = c.attr('cy');
};
dragMove = function(dx, dy) {
    var s = this, c = s.data('clone');
    c.attr({cx:c.ox+dx, cy:c.oy+dy});
};
dragStop = function() {
    this.data('clone').remove();
};
onDragOver = function(el) {
    console.log(el); // displays most of the time the clone  
};
elementToDrag.drag(dragMove, dragStart, dragStop);
elementToDrag.onDragOver(onDragOver);

【问题讨论】:

    标签: raphael clone drag


    【解决方案1】:

    在它上面睡了一晚后,我改变了克隆本身的方法,拖动原件并将克隆设置在其位置。因此我保留了原始位置,onDragOver 函数显示了正确的目标元素。

    dragStart = function() {
        var s = this, c = s.clone(); // clone stays at the original position
        s.data('clone', c);
        s.ox = s.attr('cx');
        s.oy = s.attr('cy');
    };
    dragMove = function(dx, dy) {
        var s = this;
        s.attr({cx:s.ox+dx, cy:s.oy+dy}); // but now the original is being dragged
    };
    dragStop = function() {
        var c = this.data('clone');
        this.attr({cx: c.attr('cx'), cy: c.attr('cy')}); // put original at the position of the clone
        this.data('clone').remove(); // and remove the clone
    };
    onDragOver = function(el) {
        console.log(el); // now only the targeted element is shown
    };
    elementToDrag.drag(dragMove, dragStart, dragStop);
    elementToDrag.onDragOver(onDragOver);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-16
      相关资源
      最近更新 更多