0
我執行標準的jQuery拖&拖拽功能,雖然一些細節:我使用自定義生成拖動元素(使用可拖動()初始化的輔助函數):JQuery的可棄:拿到拖動元素屬性(高度)
$("#draggingItem").draggable({
revert: 'invalid',
snap: '#myTargetTable td',
snapMode: "inner",
snapTolerance: 10,
zIndex: 100,
helper: function() {
var controlContainer = $("<div></div>");
//fill div content here
return controlContainer;
}
});
我想使可拖放區域高度適合拖動對象。
這裏是我的問題發生的地方:「over」方法 - 我無法獲得拖動元素的高度。同時ui參數在「drop」函數中可以很好地附加到容器中。
$("#myTargetTable td").droppable({
accept: "#draggingItem",
over: function (event, ui) {
var origHeight = $(this).height();
var uiHeight = $(ui).height();
if (uiHeight > origHeight) {
$(this).attr("origHeight", origHeight);
$(this).css("height", uiHeight);
}
},
out: function (event, ui) {
var origHeight = $(this).attr("origHeight");
if (origHeight) {
$(this).css("height", origHeight);
$(this).removeAttr("origHeight");
}
},
drop: function (event, ui) {
$(this).append($(ui));
}
});
Firebug的控制檯顯示錯誤消息:
NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMWindow.getComputedStyle]
我也使用$(ui.draggable).height()
嘗試,但它返回被拖原來的div,而不是由「助手」功能創建的。
你有什麼想法如何獲得拖動元素的高度?