我正在尝试创建一个能够一次展开多个面板的手风琴。我试图在jQuery UI API中找到它,但是我还没有找到正确的方法。
请让我知道如果有办法使用jQuery UI手风琴。
解决方法
正如其他人所指出的,“手风琴”小部件没有API选项直接执行此操作。但是,如果必须使用窗口小部件,则可以通过使用
beforeActivate
事件处理程序选项来颠覆并模拟窗口小部件的默认行为来实现。
例如:
$('#accordion').accordion({ collapsible:true,beforeActivate: function(event,ui) { // The accordion believes a panel is being opened if (ui.newHeader[0]) { var currHeader = ui.newHeader; var currContent = currHeader.next('.ui-accordion-content'); // The accordion believes a panel is being closed } else { var currHeader = ui.oldHeader; var currContent = currHeader.next('.ui-accordion-content'); } // Since we've changed the default behavior,this detects the actual status var isPanelSelected = currHeader.attr('aria-selected') == 'true'; // Toggle the panel's header currHeader.toggleClass('ui-corner-all',isPanelSelected).toggleClass('accordion-header-active ui-state-active ui-corner-top',!isPanelSelected).attr('aria-selected',((!isPanelSelected).toString())); // Toggle the panel's icon currHeader.children('.ui-icon').toggleClass('ui-icon-triangle-1-e',isPanelSelected).toggleClass('ui-icon-triangle-1-s',!isPanelSelected); // Toggle the panel's content currContent.toggleClass('accordion-content-active',!isPanelSelected) if (isPanelSelected) { currContent.slideUp(); } else { currContent.slideDown(); } return false; // Cancel the default action } });