1
我正在實施拖放操作,用戶可以拖動幾張圖片並將它們拖放到div中,並且我將動態追加ap標籤作爲標籤添加到每張圖片一次用戶點擊一個按鈕。將z-index設置爲動態生成的圖片標籤,以防止圖片中出現重疊標籤
目前我遇到問題時,我有兩個圖像是非常接近彼此(一個在另一個之上)。頂部圖像的附加p標籤將被底部圖像隱藏。我試圖提醒每個丟失圖像的z-index,並發現它是'自動'。我想我需要分配一個新的z-index爲每個格,但我在我追加標籤功能嘗試,它力的工作是期望:
function generateLabel() {
var current = 5000;
$('#rightframe img').each(function() {
var cImgName = $(this).attr('id');
var width = $(this).width();
// To select the respective div
var temp = "div#" + cImgName;
$.ajax({
url: '/kitchen/generatelabel',
type: 'GET',
data: { containerImgName: cImgName },
async: false,
success: function (result) {
$(temp).append(result);
// I guess the each function loop through each div according to the time it is created, so I try to assign a decreasing z-index
$(temp).css('z-index', current);
current -= 100;
// To select the label for the image
temp += " p";
// Set label width based on image width
$(temp).width(width);
}
});
});
不過,我得到的是,底部圖像稍後丟棄的圖像不會隱藏上面的圖像標籤,但如果上面的圖像比下面的圖像下落後,上面的圖像標籤被底部圖像隱藏起來。
這是一個非常特殊的情況,我希望我做的讓自己清楚......
希望能得到一些幫助這裏...感謝任何反饋...
做一些拖放操作,直到問題出現爲止......檢查這些元素的z索引。我已經扔你的腳本我認爲你不會得到你的結果,除了Z指標。 – ggzone