jQuery ui.draggable事件/状态恢复 [英] jQuery ui.draggable event/status on revert

查看:139
本文介绍了jQuery ui.draggable事件/状态恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法获取信息,如果可拖动的元素被还原?



我被困在这个。我想让一个元素再次下降,但只有当那个躺在那里的draggable被移动到别的地方(意思是不还原)。

解决方案

看起来jQuery UI不支持它,所以你可以这样添加:

  $。 ui.draggable.prototype._mouseStop = function(event){
//如果我们正在使用droppables,请通知管理器有关drop
var dropped = false;
if($ .ui.ddmanager&!this.options.dropBehaviour)
dropped = $ .ui.ddmanager.drop(this,event);

//如果一个下降来自外部(可排序)
if(this.dropped){
dropped = this.dropped;
this.dropped = false;
}

if((this.options.revert ==invalid&&!drop)||(this.options.revert ==valid&&放弃)|| this.options.revert === true ||($ .isFunction(this.options.revert)&& this.options.revert.call(this.element,dropped))){
var self = this;
self._trigger(reverting,event);
$(this.helper).animate(this.originalPosition,parseInt(this.options.revertDuration,10),function(){
event.reverted = true;
self._trigger stop,event);
self._clear();
});
} else {
this._trigger(stop,event);
this._clear();
}

return false;
}

可以让你这样做:


$ ($($){
$('#draggable')。draggable({
revert:true,
还原:function(){
console.log('reverted');
},
stop:function(event){
if(event.reverted) {
console.log('reverted');
}
}
});
});


Is there a way to get information if an element that's draggable is reverted?

I'm stuck on this. I want to make an element droppable again, but only if the draggable that was lying there is moved elsewhere (meaning doesn't revert).

解决方案

Doesn't looks like jQuery UI has support for it so you could add it yourself like this:

$.ui.draggable.prototype._mouseStop = function(event) {
    //If we are using droppables, inform the manager about the drop
    var dropped = false;
    if ($.ui.ddmanager && !this.options.dropBehaviour)
        dropped = $.ui.ddmanager.drop(this, event);

    //if a drop comes from outside (a sortable)
    if(this.dropped) {
        dropped = this.dropped;
        this.dropped = false;
    }

    if((this.options.revert == "invalid" && !dropped) || (this.options.revert == "valid" && dropped) || this.options.revert === true || ($.isFunction(this.options.revert) && this.options.revert.call(this.element, dropped))) {
        var self = this;
        self._trigger("reverting", event);
        $(this.helper).animate(this.originalPosition, parseInt(this.options.revertDuration, 10), function() {
            event.reverted = true;
            self._trigger("stop", event);
            self._clear();
        });
    } else {
        this._trigger("stop", event);
        this._clear();
    }

    return false;
}

Would allow you to do this:

$(document).ready(function($) {
    $('#draggable').draggable({
        revert: true,
        reverting: function() {
            console.log('reverted');
        },
        stop: function(event) {
            if (event.reverted) {
                console.log('reverted');
            }
        }
    });
});

这篇关于jQuery ui.draggable事件/状态恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆