2017-06-14 49 views
1

我使用「VMenu」作爲jQuery插件在HTML網站上顯示巨大的手風琴,因爲它僅支持簡單的<u><li>標籤。關閉事件中的所有手風琴選項卡

現在,我要關閉所有打開的標籤手風琴與事件/按鍵/ ...

,所以我需要你的幫助插件創建者未回答問題。

我把整個代碼的jsfiddle,但它沒有工作:https://jsfiddle.net/ekbLLcLd/3/

(function($) { 
    $.fn.vmenuModule = function(option) { 
    var obj, 
     item; 
    var options = $.extend({ 
     Speed: 220, 
     autostart: true, 
     autohide: 1 
     }, 
     option); 
    obj = $(this); 

    item = obj.find("ul").parent("li").children("a"); 
    item.attr("data-option", "off"); 

    item.unbind('click').on("click", function() { 
     var a = $(this); 
     if (options.autohide) { 
     a.parent().parent().find("a[data-option='on']").parent("li").children("ul").slideUp(options.Speed/1.2, 
      function() { 
      $(this).parent("li").children("a").attr("data-option", "off"); 
      }) 
     } 
     if (a.attr("data-option") == "off") { 
     a.parent("li").children("ul").slideDown(options.Speed, 
      function() { 
      a.attr("data-option", "on"); 
      }); 
     } 
     if (a.attr("data-option") == "on") { 
     a.attr("data-option", "off"); 
     a.parent("li").children("ul").slideUp(options.Speed) 
     } 
    }); 
    if (options.autostart) { 
     obj.find("a").each(function() { 

     $(this).parent("li").parent("ul").slideDown(options.Speed, 
      function() { 
      $(this).parent("li").children("a").attr("data-option", "on"); 
      }) 
     }) 
    } 

    } 
})(window.jQuery || window.Zepto); 

我認爲這是一個簡單的任務,但我不知道該怎麼做。

+0

從您的小提琴看來,它看起來不像數據選項屬性被添加。 – mjw

回答

1

添加此功能,並觸發其上的任何按鈕點擊:

function closeAll() 
{ 
    // obj will be your div(wrapper) within your all accordion is exist; 
    var item2 = $(".u-vmenu").find("ul").parent("li").children("a"); 
    item2.attr("data-option", "off"); 

    item2.each(function(){ 
     $(this).attr("data-option", "off"); 
     $(this).parent("li").children("ul").slideUp(200); 
    }); 
} 

此功能將關閉所有打開的手風琴。

+0

謝謝。我試過了: 但我沒有工作。 我的錯在哪裏? – elkloso

+0

可以告訴我工作的例子嗎? –

+0

下面是沒有任何設計的東西的(醜)頁面:http://www.tropho.info/de/lebensmittel.html – elkloso