gpt4 book ai didi

javascript - 拖动后如何删除对象?用户界面

转载 作者:可可西里 更新时间:2023-11-01 12:56:02 28 4
gpt4 key购买 nike

<分区>

我有代码检查 td 是否有图像,因为我想移动一个图形。我不止一次想移动我的身影,但只是在没有其他人影的地方。但是当我尝试将我的身材移回起始位置时,它确实起作用了。这是一个例子:

$(document).ready(function(){
$("#king").draggable();
$("td").droppable({
stop: function(event, ui)
{
ui.draggable.remove();
},
drop: function(event, ui) {
if($(event.target).find('img').length >0)
{
$(ui.draggable).draggable({revert:true});
}else
{
$(ui.draggable).draggable({revert:false});
var $this = $(this);
ui.draggable.position({
my: "center",
at: "center",
of: $this,
using: function(pos) {
$(this).animate(pos, 200, "linear");
}
});
}
}
});
});
td{
border: 1px black solid;
width: 90px;
height: 90px;
}
img{
width: 80px;
height: 80px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<table>
<tr>
<td id="drop_one"><img src="http://www.houseofchess.com/images/chess_pieces/wooden_staunton/shared/216777-375/nqw.jpg" id="king"></td>
<td id="drop_two"></td>
</tr>
<tr>
<td id="drop_one"><img src="http://www.houseofchess.com/images/chess_pieces/wooden_staunton/shared/216777-375/nqw.jpg" id="king"></td>
<td id="drop_two"></td>
</tr>
</table>

如你所见,我试图在停止后删除它,但那只是愚蠢的尝试。我怎样才能从起始位置删除图像以便我可以回到它?或者我应该更改我的 if 以检查字段中是否有图像的不同方式?

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com