jQuery draggable helper不可拖动?

时间:2016-03-10 19:00:53

标签: jquery jquery-ui jquery-ui-draggable

我有一个带有'.item'类的可拖动项目,一旦我将它拖到目的地它只是坐在那里我无法移动它,这是我正在使用的代码:

        $('.item').draggable({
            helper : 'clone',
            onStartDrag:function(){
                $(this).draggable('options').cursor = 'not-allowed';
                $(this).draggable('clone').css('z-index',10);
            },
            onStopDrag:function(){
                $(this).draggable('options').cursor='move';
            }
        });

        $('.cart').droppable({
            drop: function(event, ui) {
                $.ui.ddmanager.current.cancelHelperRemoval = true;
            },
            onDragEnter:function(e,source){
                $(source).draggable('options').cursor='auto';
            },
            onDragLeave:function(e,source){
                $(source).draggable('options').cursor='not-allowed';
                $.ui.ddmanager.current.cancelHelperRemoval = false;
            },
            onDrop:function(e,source){
                var name = $(source).find('p:eq(0)').html();
                var price = $(source).find('p:eq(1)').html();
                addProduct(name, parseFloat(price.split('$')[1]));
            }
        });

1 个答案:

答案 0 :(得分:2)

在Dropppable方法中修改掉落函数

 $(".item").draggable({
    helper:'clone',
    onStartDrag:function(){
            $(this).draggable('options').cursor = 'not-allowed';
            $(this).draggable('clone').css('z-index',10);
        },
        onStopDrag:function(){
            $(this).draggable('options').cursor='move';
        }
});  

$(".cart").droppable({
    accept: ".item",
    drop: function(event,ui){
        var new_signature = $(ui.helper).clone().removeClass('item');
        new_signature.draggable();
        $(this).append(new_signature);
    },
     onDragEnter:function(e,source){
            $(source).draggable('options').cursor='auto';
        },
        onDragLeave:function(e,source){
            $(source).draggable('options').cursor='not-allowed';
            $.ui.ddmanager.current.cancelHelperRemoval = false;
        },
        onDrop:function(e,source){
            var name = $(source).find('p:eq(0)').html();
            var price = $(source).find('p:eq(1)').html();
            addProduct(name, parseFloat(price.split('$')[1]));
        }
});