2017-05-02 150 views
0

---原來哈弗代碼---需要幫助改變菜單從懸停點擊

function bind_dropdown() { 
    $('div#quick_nav div.search_dropdown').on('hover', function() { 
     var thisid = $(this).attr('id').split('_'); 
     var this_action = thisid[1]; 
     var this_width = 950; 
     var add_class = 'dropdown_full'; 

     if(this_action == 4) { 
      this_width = 200; 
      add_class = 'dropdown_small'; 
     } 

     if($('div#quick_nav div#dropdown_'+escape(this_action)).is(':visible')) { 
      $('div#quick_nav div#dropdown_'+escape(this_action)).addClass(add_class).slideUp(100); 
     } 
     else{ 
      $('div#quick_nav div.dropdown').hide(); 
      $('div#quick_nav div#dropdown_'+escape(this_action)).addClass(add_class).slideDown(100).width(this_width); 
     } 
     return false; 
    }); 
} 

---結束原始代碼---

我曾嘗試和改變懸停點擊。然而,它可以關閉菜單,您現在必須再次單擊菜單圖標。任何幫助將不勝感激。我希望能夠點擊來顯示菜單,當鼠標離開菜單時它會自動關閉。

預先感謝您

Ĵ

+2

使用onClick事件顯示菜單和OnMouseLeave在將其隱藏。 –

回答

0

使用下面的代碼

function bind_dropdown() { 
    $('div#quick_nav div.search_dropdown').on('click', function() { 
     var thisid = $(this).attr('id').split('_'); 
     var this_action = thisid[1]; 
     var this_width = 950; 
     var add_class = 'dropdown_full'; 

     if(this_action == 4) { 
      this_width = 200; 
      add_class = 'dropdown_small'; 
     } 

     if($('div#quick_nav div#dropdown_'+escape(this_action)).is(':visible')) { 
      $('div#quick_nav div#dropdown_'+escape(this_action)).addClass(add_class).slideUp(100); 
     } 
     return false; 
    }).on("mouseleave", function() { 
     var thisid = $(this).attr('id').split('_'); 
     var this_action = thisid[1]; 
     var this_width = 950; 
     var add_class = 'dropdown_full'; 

     if(this_action == 4) { 
      this_width = 200; 
      add_class = 'dropdown_small'; 
     } 
     $('div#quick_nav div.dropdown').hide(); 
     $('div#quick_nav div#dropdown_'+escape(this_action)).addClass(add_class).slideDown(100).width(this_width); 
    }); 
}