Droppable在DROP之后触发OUT事件

问题描述 投票:0回答:1

我有一批小石头,可以拖拉,可以分成几组扔掉。为了正确突出显示,我使用了OVER和OUT事件。但是我对DROP和OUT事件有一些麻烦。当我在组中拖放一块石头时,会触发OVER和DROP事件,但是一旦我拿起下一块石头(将其移动到足以超出拖动阈值的程度),“旧” OUT事件就会触发触发。

有人遇到过同样的问题,可以帮助我吗?

我的可放置对象,即小组,被这样设置:

   $('.group').droppable({
        accept: this.canItBeDropped.bind(this),
        drop: this.drop.bind(this),
        over: this.over.bind(this),
        out: this.out.bind(this),
    });

还有我的可拖动物品,石头,像这样:

    this.$stone.draggable({
        distance: 3,
        revert: 'invalid',
        revertDuration: 400,
        scroll: false,
        stack: '.stone',
        refreshPositions: true, 
    });

编辑

[进一步研究了库之后,我发现它与我的自定义接受函数有关。但是图书馆用新石头来称呼它,而不是我所期望的旧石头。

javascript jquery jquery-ui jquery-ui-draggable jquery-ui-droppable
1个回答
0
投票
麻烦的原因是,一旦我放下一块石头,我的自定义accept函数就会返回false,因为现在这块石头已经不适合它了(这是我的项目的要求)] >

所以我的解决方法是只在实际删除之前确定if语句的结果

drop: function( draggable, event ) { var dropped = false; // Create a copy of the droppables in case the list changes during the drop (#9116) $.each( ( $.ui.ddmanager.droppables[ draggable.options.scope ] || [] ).slice(), function() { if ( !this.options ) { return; } // determine the result for the if statement beofre the dropping let deactivate = !this.options.disabled && this.visible && this.accept.call( this.element[ 0 ], ( draggable.currentItem || draggable.element ) ) if ( !this.options.disabled && this.visible && intersect( draggable, this, this.options.tolerance, event ) ) { dropped = this._drop.call( this, event ) || dropped; } if (deactivate) { this.isout = true; this.isover = false; this._deactivate.call( this, event ); } } ); return dropped; }

© www.soinside.com 2019 - 2024. All rights reserved.