我正在使用Foundation 6的Accordion功能,并在一个页面上有三个独立的手风琴。默认情况下,在一个手风琴中,您一次只能展开一个内容。但是,我想在整个页面上只为一部手风琴打开一个内容。
我很确定我可以使用他们的方法完成此操作,特别是“Up”方法,但是我找不到任何有用的示例,他们的文档非常稀疏。这就是他们提供的全部内容:
up
$('#element').foundation('up', $target);
Closes the tab defined by $target.
http://foundation.zurb.com/sites/docs/accordion.html
我不确定从哪里开始......到目前为止,这就是我所拥有的:
JS:
$(".accordion-title").click(function(e) {
//Not sure what to do with this
$('#element').foundation('up', $target);
});
HAML:
%ul.accordion#accordion-1{:'data-accordion' => "", :'data-allow-all-closed' => "true"}
%li.accordion-item
%a.accordion-title
Title 1
.accordion-content{:'data-tab-content' => ""}
Content 1
%li.accordion-item
%a.accordion-title
Title 2
.accordion-content{:'data-tab-content' => ""}
Content 2
%ul.accordion#accordion-2{:'data-accordion' => "", :'data-allow-all-closed' => "true"}
%li.accordion-item
%a.accordion-title
Title 1
.accordion-content{:'data-tab-content' => ""}
Content 1
%li.accordion-item
%a.accordion-title
Title 2
.accordion-content{:'data-tab-content' => ""}
Content 2
%ul.accordion#accordion-3{:'data-accordion' => "", :'data-allow-all-closed' => "true"}
%li.accordion-item
%a.accordion-title
Title 1
.accordion-content{:'data-tab-content' => ""}
Content 1
%li.accordion-item
%a.accordion-title
Title 2
.accordion-content{:'data-tab-content' => ""}
Content 2
答案 0 :(得分:3)
我发现问题的解决方案,以防其他人被卡住:
$(".accordion-title").click(function(e) {
$('.accordion').foundation('up', $('.accordion .accordion-item.is-active .accordion-content'));
});
答案 1 :(得分:1)
我无法得到alexandraleigh的工作答案,它也关闭了我刚刚点击打开的手风琴。
以下是我最后写的内容。它适用于使用data-multi-expand="true"
或data-multi-expand="false"
/**
* on accordion section click
*/
$('.accordion-title').on('mouseup', function (e) {
var $accordionItem = $(this).parent(),
//is the section hidden? if the section is not yet visible, the click is to open it
opening = ($accordionItem.find('.accordion-content:hidden').length === 1);
//
if (opening) {
//the accordion that has just been clicked
var $currentAccordion = $accordionItem.parent();
//close all other accodions
$('.accordion').each(function () {
var $acc = $(this);
//ignore the accordion that was just clicked
if ($acc[0] !== $currentAccordion[0]) {
//find any open sections
var $openSections = $acc.find('.accordion-item.is-active .accordion-content');
//
$openSections.each(function (i, section) {
//close them
$acc.foundation('up', $(section));
});
}
});
}
});
答案 2 :(得分:1)
我无法获得r8n5n的工作答案 - 也许是因为基金会的更新。但我设法让它在v6.3.0上使用以下内容..
jQuery('.accordion-title').on('mouseup', function (e) {
jQuery('.accordion').each(function () {
jQuery(this).foundation('up', jQuery('.accordion-content'));
});
});
答案 3 :(得分:0)
我对先前的答案有想法
如果您有2个手风琴,只需为其添加类名。例如class =“ accordion手风琴第一”和class =“ accordion手风琴第二”。
//close active item on second accordion when click on first accordion
$(".accordion-first .accordion-title").click(function(e) {
$('.accordion').foundation('up', $('.accordion-second .accordion-item.is-active .accordion-content'));
});
//close active item on first accordion when click on second accordion
$(".accordion-second .accordion-title").click(function(e) {
$('.accordion').foundation('up', $('.accordion-first .accordion-item.is-active .accordion-content'));
});