2016-12-29 57 views
0

如何將超級菜單懸停更改爲點擊?如何更改大型菜單懸停在小屏幕尺寸點擊?

$(function() { 
 
    $(".dropdown").hover(
 
     function() { 
 
      $('.dropdown-menu', this).stop(true, true).fadeIn("slow"); 
 
      $(this).toggleClass('open'); 
 
     }, 
 
     function() { 
 
      $('.dropdown-menu', this).stop(true, true).fadeOut("slow"); 
 
      $(this).toggleClass('open'); 
 
     }); 
 
});

我改變.hover到。點擊,但它不工作。

+0

你能提供JSFIDDLE嗎? –

+0

我是新來的,不知道該怎麼做。 – Ezatla

回答

0

您需要複製懸停關閉方法。如果沒有DOM,也很難確定,但是像這樣的東西應該可以工作。

$(function() { 
    $(".dropdown").click(function() { 
    if($(this).hasClass('open')) { 
     $('.dropdown-menu', this).stop(true, true).fadeOut("slow"); 
     $(this).toggleClass('open'); 
    } else { 
     $('.dropdown-menu', this).stop(true, true).fadeIn("slow"); 
     $(this).toggleClass('open'); 
    } 
    }); 
}); 

基本上你需要檢查,看看是否打開菜單,並運行,通常會火的時候,您取消懸停,如果它是代碼。

希望這會有所幫助。

+0

我想刪除鏈中的'.stop()'方法。除此之外,如果沒有工作演示,就很難知道發生了什麼問題。你能舉一個jsFiddle爲例嗎? – Ivan

+0

瀏覽器說意外令牌(我認爲有什麼不對的代碼,你可以檢查一下嗎? – Ezatla

+0

這樣的事情。我已經更新我的答案。 https://jsfiddle.net/7LdpawLL/ – Ivan