0
我希望有人能帮助我解决问题。现在我正在做jquery拖放。 我的问题是,当用户拖动和放置图像放置区域。该下拉区域就像树图。所以放置区域应该像树图一样。但现在我可以放在矩形区域。我不知道我该如何解决这个问题。任何人都可以帮助我。jquery拖放位置
我使用以下编码。
$j("#draggable").draggable({
revert: function (dropped) {
var $jdraggable = $j(this),
hasBeenDroppedBefore = $jdraggable.data('hasBeenDropped'),
wasJustDropped = dropped && dropped[0].id == "tree";
if (wasJustDropped) {
//centering with css
centerPopup();
//load popup
loadsharePopup();
return false;
} else {
if (hasBeenDroppedBefore) {
return true;
} else {
return true;
}
}
}
});
$j("#tree").droppable({
activeClass: 'ui-state-hover',
hoverClass: 'ui-state-active',
drop: function (event, ui) {
//var Stoppos = $j(this).position();
//alert("STOP: \nLeft: "+ Stoppos.left + "\nTop: " + Stoppos.top);
var newPosX = ui.offset.left - $j(this).offset().left;
var newPosY = ui.offset.top - $j(this).offset().top;
//alert($j(this).offset().left);
$j("#txtPosX").val(newPosX);
$j("#txtPosY").val(newPosY);
//alert("STOP: \nLeft: "+ newPosX + "\nTop: " + newPosY);
$j(this).addClass('ui-state-highlight').find('p').html('Dropped!');
$j(ui.draggable).data('hasBeenDropped', true);
}
});
});
<div id="tree">
<div id="draggable"></div>
</div>
哪里是你的代码,你尝试过什么? –
我在上面的问题中包含了我的编码。 – sandy
非常感谢你的回答。我会试着用这个 – sandy