如何通过jquery中的可拖动事件来限制其他事件的调用

时间:2016-01-08 09:54:43

标签: jquery jquery-ui events

我实际上被困在这里。我在jquery中使用拖动停止事件。每当我拖动一个元素并且当它的停止事件被触发时,其他事件也会被执行(未从停止调用的事件)。我使用 event.stopPropagation()来限制其他事件被执行。但它真的不起作用。以下是我正在使用的代码:

function RegisterServicesDraggableEvent(serviceElement) {
$(serviceElement).draggable({
    grid: [26, 0],
}, {
    drag: function (event, ui) {
        event.stopPropagation();
        $(this).find('.count-popup').css('display', 'none');
        $(this).find('.detail-popup').css('display', 'none');            
        $(this).parents('.timeline-bar').find('.add-new-service').hide();
        var parentLength1 = $(this).parents('.timeline-bar').find('.bar-steps').width();
        var parentLength2 = $(this).parents('.timeline-bar').find('.bar-steps').position().left;
        var parentLength3 = parentLength1 + parentLength2;
        var rightHighestValue = (parentLength3) - 28;
        var leftHighestValue = (parentLength2) + 7;
        if (ui.position.left < leftHighestValue) {
            ui.position.left = leftHighestValue;
        }
        if (ui.position.left > rightHighestValue) {
            ui.position.left = rightHighestValue;
        }
    },
    stop: function (event, ui) {
        event.stopPropagation();            
        ClosePopups();            

        //update popup for this priority
        SetServicesPopup($(this).parents('.timeline-bar'), priorityObj);                    
        $('.priority-timeline .timeline-list').removeClass('selected');
        $(this).parents('.timeline-list').addClass('selected');
        $(this).parents('.timeline-list').find('.priority-icon').removeClass('selected');
        $(this).addClass('selected');
        //display the activity details    
        DisplayActivityDetail($(this), false);
        $(".service-timeline .activities").find('.edit-row.input-edit').each(function () {
            if ($(this).parents('.activities').hasClass('active'))
                $(this).parents('.activities').find('.sheduled-date').hide();
            else {
                $(this).parents('.activities').find('.sheduled-date').show();
            }
        });   


    }
});

}

调用stop事件后,将添加以下类并应用css。但是,只要代码完成执行,控件就会传递给另一个事件并开始执行,从而返回否定结果。

任何建议都会受到赞赏,因为我真的被困在这里..

谢谢,

0 个答案:

没有答案