2010-10-18 81 views
0

我的代碼有一些divs出現在屏幕上根據不同的行動。該div有句柄,使他們可以通過jquery ui.draggable代碼拖動。我有可拖動的ui堆棧選項集,這樣當你拖動一個項目時,它會自動移動到所有其他可拖動項目的前面。如何調用jQuery的拖拽事件

我遇到的問題是,我想要一個div移動到前面,即使您只需單擊該手柄,而無需將其拖動到任何位置。我試過在單擊句柄時觸發各種事件,例如mousedown,mousemove,mouseup,drag,dragstart和dragstop,但似乎沒有任何技巧。我也嘗試改變z-index值,但迄今爲止效果並不理想。

我的代碼看起來像這樣。說我有div,手柄是一個h5標籤。我已經實例化了可拖動的函數。所以我有:

$("div.window h5").click(function() { 
    $(this).parents("div:first").trigger("whatever event i am trying"); 
)}; 

但這是行不通的。 (我也嘗試把觸發器放在h5本身而不是父div上)。我沒有看到錯誤,我只是沒有得到預期的結果。

在此先感謝您的幫助!

回答

2

試試這個:

$("div.window h5").click(function(e){ 

    // Variable to hold the highest z-index 
    var largestZ = 1; 

    // I have used div.window h5 but this should cycle through each draggable element 
    $("div.window h5").each(function(i) { 
     // Get the the z-index and update if it is larger than current largest value 
     var currentZ = parseFloat($(this).css("zIndex")); 
     largestZ = currentZ > largestZ ? currentZ : largestZ; 
    }); 

    $(this).css("z-index", largestZ + 1); 
}); 

一些選擇的可能需要改變,因爲我看不到你的全部代碼。我發現這個片段,並從here修改它。

+0

這樣做!非常感謝! – Gary 2010-10-18 16:38:50