我設法讓一個div在另一個div的範圍內下降,然後讓它變成可拖動的。但最初的div仍然存在。我將如何去隱藏或刪除它?需要隱藏後初始div
HTML:
<html><body>
<div class="dragImg">
<img src="http://i.dailymail.co.uk/i/pix/2008/06/04/article-0-0179864B00000578-284_224x423.jpg" width="50" height="94" class="img"></div>
</div>
<div id="dropHere"></div>
</body></html>
JS:
<script type="text/javascript">
$(function(){
//Make every clone image unique.
var counts = [0];
var resizeOpts = {
handles: "none" ,autoHide:true
};
$(".dragImg").draggable({
helper: "clone",
//Create counter
start: function() { counts[0]++; }
});
$("#dropHere").droppable({
drop: function(e, ui){
if(ui.draggable.hasClass("dragImg")) {
$(this).append($(ui.helper).clone());
//Pointing to the dragImg class in dropHere and add new class.
$("#dropHere .dragImg").addClass("item-"+counts[0]);
$("#dropHere .img").addClass("imgSize-"+counts[0]);
//Remove the current class (ui-draggable and dragImg)
$("#dropHere .item-"+counts[0]).removeClass("dragImg ui-draggable ui-draggable-dragging");
$(".item-"+counts[0]).dblclick(function() {
$(this).remove();
});
make_draggable($(".item-"+counts[0]));
$(".imgSize-"+counts[0]).resizable(resizeOpts);
}
}
});
var zIndex = 0;
function make_draggable(elements)
{
elements.draggable({
containment:'parent',
start:function(e,ui){ ui.helper.css('z-index',++zIndex); },
stop:function(e,ui){
}
});
}
});
</script>
這裏是我的全代碼和演示JFiddle:http://jsfiddle.net/2rxC4/6/
你只需要一個div? –
Jsut給了div一個id,然後在drop事件中刪除它http://jsfiddle.net/2rxC4/8/ –