代码之家  ›  专栏  ›  技术社区  ›  cdarwin

停止拖动后立即重新启动拖动

  •  1
  • cdarwin  · 技术社区  · 6 年前

    如何在停止后立即重新启用拖动?

    this.layer = new Konva.Layer({draggable : true});
    
    function myPosition() {
         ...
    }
    
    var that = this;
    this.layer.dragBoundFunc( 
        function(pos) {
            var y = pos.y;
            if (y + myPosition()<0) {
                this.stopDrag();
                setTimeout(function() {that.layer.startDrag();}, 30);
            }
            if (y+myPosition()>50) {
                this.stopDrag();
                setTimeout(function() {that.layer.startDrag();}, 30);
            }               
            return {
                x : this.getAbsolutePosition().x,
                y : y
            };
        });
    
    0 回复  |  直到 6 年前