我正在使用jquery拖放功能。现在我想只丢弃图像映射区域。如果光标落在图像映射之外,则可拖动区域应返回false。有人帮帮我。
以下是我的编码
$ j(function(){
$j("#draggable").draggable({
revert: function (dropped) {
var $jdraggable = $j(this),
hasBeenDroppedBefore = $jdraggable.data('hasBeenDropped'),
wasJustDropped = dropped && dropped[0].id == 'treearea';
alert(wasJustDropped);
if (wasJustDropped) {
//centering with css
centerPopup();
//load popup
loadsharePopup();
return false;
} else {
if (hasBeenDroppedBefore) {
return true;
} else {
return true;
}
}
}
});
$j("img#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);
}
});
});