2011-09-24 85 views
2

z-index的問題,這是我的代碼(請參閱​​):與助手克隆

$('.first').draggable({ 
    cancel: null, 
    helper: 'clone' 
}); 

$('.second').droppable({ 
    over: function(event, ui) { 
     $(this).css('z-index', 1); 
     ui.helper.css('z-index', 0); 
    } 
}); 

我想有輔助克隆去可放開元素下,當它被拖到它。我究竟做錯了什麼?

回答

5

當你拖動.first元素,生成的拖動元素定位在.second元素之後絕對增加。絕對定位的元素獲得更高的優先級。要解決此問題,請使用ui.helper.css('z-index', "-1");而不是ui.helper.css('z-index', 0);

+0

謝謝!爲什麼修復工作? – Randomblue

+0

*「絕對定位的元素獲得更高的優先級」* =破壞您的代碼。歸納一個負Z指數可以翻譯爲*「不要丟我,我不重要」*。 –