0

我在项目中使用 gridster.net,我遇到了问题。

我试图让小部件在单击后按住鼠标一秒钟后才开始拖动。我正在使用下一个代码:

$(".gridster .gs-w").on('mousedown', function(e) {
    gridsterObj.disable();
    dragTimeout = setTimeout(function() {
        gridsterObj.enable();
    }, 500);
}).bind('mouseup mouseleave', function() {
    clearTimeout(dragTimeout);
});

但它没有用。似乎我必须调用开始拖动的函数,例如gridsterObj.on_start_drag.call(gridsterObj, e, ui);,但是我在哪里可以获得 UI 对象?它在 gridster 代码中随处可见,但我找不到它创建的位置。它似乎是 jquery UI 对象。我怎样才能创建它?

4

2 回答 2

1

您应该能够将 UI 对象引用为$.uiwindow.jQuery.ui

所以你的代码应该是这样的:

$(".gridster .gs-w").on('mousedown', function(e) {
    gridsterObj.disable();
    dragTimeout = setTimeout(function() {
        gridsterObj.enable();
        gridsterObj.on_start_drag.call(gridsterObj, $.ui);
    }, 500);
}).bind('mouseup mouseleave', function() {
    clearTimeout(dragTimeout);
});
于 2014-05-07T18:27:34.553 回答
0

我以下一个代码结束:

$(".gridster .gs-w").on('mousedown', function(e, data) {
    var self = this;

    if (!data || !data.start) {
        gridsterObj.disable();

        dragTimeout = setTimeout(function() {
            gridsterObj.enable();
            $(self).trigger(e, [{ start: true }]);
        }, 500);
    } else {
        $(self).addClass('dragging');
    }
}).bind('mouseup mouseleave', function() {
    clearTimeout(dragTimeout);
});

这样,gridster 在开始拖动之前有 0.5 秒的延迟。

于 2014-05-08T07:04:42.367 回答