2013-05-08 91 views
0

我正在創建一個jQuery菜單欄,並且所有內容都看起來不錯,但是當我將鼠標放在頂級菜單項上有一個子菜單,其中第一個菜單項也有一個子菜單時,會產生奇怪的效果。如果我將鼠標移入和移出(在View菜單項左右移動)20次,我將開始看到View> Encoding子菜單向右移動的次數越來越多。jQuery用戶界面Menubar幻影子菜單問題

我可以用修改後的菜單欄演示示例重新創建問題。我在Firefox 20.0.1上。

在這裏看到:http://jsfiddle.net/Njjgm/

我想,這是找到subsub菜單的右側邊緣,然後設置相同subsub菜單到該位置的新的左邊緣......所以,如果我放慢了開盤或修復定位數學,然後我不應該有這個錯誤。

我正在尋找jquery.ui.menubar.js文件,看看我是否可以調整setTimeouts,或修復subub菜單定位但沒有任何運氣。

我在看這個(從jquery.ui.menubar.js線262):

__applyMouseBehaviorForSubmenuHavingMenuItem: function (input, menubar) { 

    var menu = input.next(menubar.options.menuElement), 
     mouseBehaviorCallback = function(event) { 
      // ignore triggered focus event 
      if (event.type === "focus" && !event.originalEvent) { 
       return; 
      } 

      if (event.type === "mouseenter") { 

       this.element.find(":focus").focusout(); 
       if (this.stashedOpenMenu) {      
        this._open(event, menu); 
       } 
       this.stashedOpenMenu = undefined; 
      } 
      if ((this.open && event.type === "mouseenter") 
           || this.options.autoExpand) { 

       if (this.options.autoExpand) { 

        clearTimeout(this.closeTimer); 
       } 
       this._open(event, menu); 
      } 
     }; 

而且也是在這個:(從jquery.ui.menubar.js 68行)

focusin: function(event) { 
      clearTimeout(menubar.closeTimer); 
     }, 
     focusout: function(event) { 
      menubar.closeTimer = setTimeout (function() { 
       menubar._close(event); 
      }, 150); 
     }, 
     "mouseleave .ui-menubar-item": function(event) { 
      if (menubar.options.autoExpand) { 
       menubar.closeTimer = setTimeout(function() { 
        menubar._close(event); 
       }, 150); 
      } 
     }, 
     "mouseenter .ui-menubar-item": function(event) { 
      clearTimeout(menubar.closeTimer); 
     } 

已經看到和之前修復此人與jQuery用戶界面菜單欄的經驗?有誰知道setTimeout的修復? HoverIntent似乎使用與菜單欄相同的set/clearTimeout技術,所以我不想從菜單欄中刪除所有邏輯以添加它。歡迎任何建議。謝謝。

回答

0

嗯,我找到了解決這個問題的方法,雖然我沒有修復錯誤定位(但我想我找到了它可以修復的地方)。

默認情況下代碼選擇打開菜單中的第一個列表元素,如果該元素也有菜單,該菜單也會打開。我拿出那把焦點的第一個子元素的代碼(爲什麼它甚至需要做到這一點?)

從jquery.ui.menubar.js線451

this.active = menu 
     .show() 
     .position($.extend({ 
      of: button 
     }, this.options.position)); 
     //.removeAttr("aria-hidden") 
     //.attr("aria-expanded", "true") 
     //.menu("focus", event, menu.children(".ui-menu-item").first()) 
     // TODO need a comment here why both events are triggered 
     //.focus() 
     //.focusin(); 

和急,Changeo!沒有更多的幻影下拉菜單...我可以試圖找出menu.position,但這對我有效。