2016-11-28 27 views
0

請幫助我我是新的j查詢和角度 我有1個div它是另一個div的容器我想要限制拖動div包含class XYZ如何限制包含class =「XYZ」的div div

+0

你有沒有試過這個http://stackoverflow.com/questions/704564/disable-drag-and-drop-on-html-elements? – TechnoCrat

+0

你可以使用'draggable'函數的'cancel'屬性。 [小提琴](https://jsfiddle.net/pandeyvishal1986/fe8y7xjq/#&togetherjs=51hA9rDIwE)願它幫忙! – RonyLoud

+0

是的,我用過,但沒有工作 –

回答

1

使用屬性的draggablecancel功能fiddle

JS:

$('.drag').draggable({ 
    cancel: ".xyz", 
    helper: function(){ 
     return "<span>Dragging</span>"; 
    } 
}); 
$('#drop').droppable({ 
    accept: 'div', 
    drop: function(e,ui){ 
     ui.draggable.text('I am draggable') 
    } 
}) 

HTML:

<div class="drag">I can be dragged</div> 
<div class="drag xyz">I cannot be dragged</div> 
<br/> 
<br/> 
<div id="drop">Drop Here</div>