在jQuery中拖动时,元素不能具有z-index最大值

时间:2012-12-20 09:27:10

标签: jquery jquery-ui drag-and-drop

我有一个可拖动的项目,但当我拖动它时,它在其他html元素下,即使我设置.item_dragable { cursor: move; z-index: 2147483646; } 以及可拖动的事件:

jQuerydragable.draggable({
    cancel: "a.ui-icon", // clicking an icon won't initiate dragging
    revert: "invalid", // when not dropped, the item will revert back to its initial position
    containment: "document",
    helper: "clone",
    cursor: "move",
    zIndex: 2147483647
});

它有什么不对?我使用最新的jQuery和jQuery ui

感谢

1 个答案:

答案 0 :(得分:4)

让您的可拖动项目覆盖其他所有内容的最佳方法是使用选项appendTo(请参阅jQuery UI doc)并将其设置为"body",如下所示:

jQuerydragable.draggable({
    cancel: "a.ui-icon", // clicking an icon won't initiate dragging
    revert: "invalid", // when not dropped, the item will revert back to its initial position
    containment: "document",
    helper: "clone",
    cursor: "move",
    zIndex: 100000,
    appendTo: "body"
});

当然设置一个足够大的z-index来高于其他所有。