看起來問題是由droppable's tolerance option造成的;其默認值是intersect
。
如在API文檔
intersect
指出:可拖動的在兩個方向 重疊可投放至少50%。
鑑於你<li>
S如何仍處於默認的風格,他們將填補他們的父母<ul>
的可用寬度,如果你嘗試拖動他們在桌子的右邊<li>
超過50%掛在可丟棄物之外。
通過爲您的<li>
s和#myListOfData
添加一些邊界,您可以更好地瞭解發生了什麼。
Figure 1
所以現在我們知道是什麼問題,到解決方案。
可以作爲Pepper說只是改變可投放的耐受性選項指針:
Working Example 1
$('#table').droppable({
tolerance: 'pointer', //Important Bit
over: function (event, ui) {
$('#tableOverlay').width($(this).width());
$('#tableOverlay').height($(this).height());
$('#tableOverlay').show();
$("#tableOverlay").position({
of: this,
at: "top left",
my: "top left"
});
},
out: function (event, ui) {
$('#tableOverlay').hide();
},
drop: function (event, ui) {
$('#tableOverlay').hide();
}
});
或者你可以使用tolerance option: 'touch'
像這樣:
Working Example 2
$('#table').droppable({
tolerance: 'touch', //Important Bit
over: function (event, ui) {
$('#tableOverlay').width($(this).width());
$('#tableOverlay').height($(this).height());
$('#tableOverlay').show();
$("#tableOverlay").position({
of: this,
at: "top left",
my: "top left"
});
},
out: function (event, ui) {
$('#tableOverlay').hide();
},
drop: function (event, ui) {
$('#tableOverlay').hide();
}
});
或者你可以像這樣指定一個寬度爲您<li>
S:
Working Example 3
#myListOfData li {
width: 100px;
}
或者,如果你寧願不改變公差選項或指定的寬度,你可以使用
display: table;
像這樣:
Working Example 4
#myListOfData li {
display: table;
}
感謝您的難以置信的答案!希望胡椒獎給你賞金,你肯定值得這個詳細的答案:) – Johannes