2016-03-10 3 views
0

У меня есть перемещаемый элемент с классом «.item», когда я перетащить его к месту назначения он просто сидит там, и я не могу переместить его вокруг, это код, я использую:jQuery draggable helper не перетаскивается?

 $('.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])); 
      } 
     }); 

ответ

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])); 
     } 
}); 
+0

но цель помощника, чтобы сделать копию элемента, а не перетаскивать исходный элемент. –

+0

ok, i undrestand you, я снова пересмотрел код –

+0

Спасибо за помощь @Yasemin, но теперь элемент даже не попадает на класс тележки, я могу перетащить его, но когда я его уронил, он просто исчезает. –

Смежные вопросы