2013-02-19 64 views
1

這是我在很短的形式問題:我想有分裂的按鈕與菜單中(使用jQuery UI的看到的結果:jqueryui-demo,它做不影響定位其他任何東西。所以第二個按鈕不應該移動,如果第一個分割按鈕顯示它的菜單,在jsfiddle明顯錯誤。我知道可以將位置屬性改爲絕對的,但是,我真的不想計算每個位置(並重新計算它,如果更改或document.size()更改...jQuery的(1.10.1)菜單覆蓋

有沒有什麼辦法告訴jquery.menu它應該覆蓋我的菜單?

的的jsfiddle歸結爲以下幾點:

的JavaScript

$(function() { 
    $.each($(".key"), convert); 

}); 

function convert(index, element) { 
    //retrieve button-value 
    var key = $(element).text(); 
    //exchange elements html with the split-button and the menu 
    $(element).html(
     '<div><div><button class="KeywordTag">' + key + '</button> 
      <button class="selectButton">Options</button></div> 
      <ul> 
      <li><a href="#" class="addtoquery">Add to Query</a></li> 
      <li><a href="#" class="opentab">Open in new Tab</a></li> 
      <li><a href="#" class="addtoquerytab">Add to Query in new Tab</a></li> 
      </ul></div>'); 
    //call jquery.button(...) to turn the buttons into good looking buttons the the 
    //unordered list into a menu 
    //... 
    //add event handling 
    //... 
    } 

CSS

//for round borders... 
//I'd probably need to change the position attribute, but I really don't want to 
//have to calculate each position by hand... 
.KeywordTag { 
    -moz-border-topleft-radius: 75px; 
    -moz-border-bottomleft-radius: 75px; 
    -webkit-border-topleft-radius: 75px; 
    -webkit-border-bottomleft-radius: 75px; 
    border-bottom-left-radius:75px; 
    border-top-left-radius:75px; 
} 
.selectButton { 
    -moz-border-topright-radius: 75px; 
    -moz-border-bottomright-radius: 75px; 
    -webkit-border-topright-radius: 75px; 
    -webkit-border-bottomright-radius: 75px; 
    border-bottom-right-radius:75px; 
    border-top-right-radius:75px; 
} 

HTML

<!-- Those spans will be exchanged with 
    the actual buttons and menus by the javascript above --> 
<span class="key">examplekey</span> 
<span class="key">examplekey2</span> 
+0

你舉的例子有錯誤,請修復。 – Dom 2013-02-19 21:54:13

+0

對不起,有一個檢查缺少包括jquery-UI – 2013-02-19 22:34:11

回答

2

因爲我今天早上解決了我的問題,並且想爲其他人記錄解決方案,我正在回答我自己的問題。

如果您將<ul>定義爲<ul style='position: absolute; z-index=1'>,您將獲得所需的行爲。

參見:http://jsfiddle.net/crapman/VUBqK/7/Screenshot with Example