[英]How to Expand All/Collapse All Using Adi Palaz's Nested Accordion
Adi Palaz's Nested Accordion Adi Palaz的嵌套手风琴
This seems like it should be simple but I can't seem to figure this out and I have been sitting here slamming my head on my desk after like four hours without a solution. 这似乎很简单,但我似乎无法弄清楚,我坐在这里就像在四个小时后没有解决办法一样,把头砸在桌子上。
You will notice in the demo on the page that there are expand all/collapse all buttons that fire a function to open all the accordion panels or close them. 您会在页面上的演示中注意到,有全部展开/全部折叠按钮可以触发打开或关闭所有手风琴面板的功能。
I DON'T want to use those buttons. 我不想使用这些按钮。 I want to write my own function and fire the expand all or collapse all function after the user completes a gesture on a DIV somewhere else on the page.
我想编写自己的函数,并在用户在页面上其他位置的DIV上完成手势后触发全部展开或折叠全部功能。
But I can't seem to figure out how to call the same function the author is using on the buttons to properly expand and collapse the accordion panels. 但是我似乎无法弄清楚如何调用作者在按钮上使用的相同功能来正确展开和折叠手风琴面板。
If it helps, I set up a test page to play with: http://dl.dropbox.com/u/22224/Newfolder/nested_accordion_demo3.html 如果有帮助,我将设置一个测试页面以供使用: http : //dl.dropbox.com/u/22224/Newfolder/nested_accordion_demo3.html
And here are the two scripts it needs to work: 这是它需要工作的两个脚本:
Nested Accordion Script 嵌套手风琴脚本
Please help! 请帮忙! I am desperate and the author is not responding to emails!
我很拼命,作者没有回复电子邮件!
I was able to solve the expand/collapse all problem with the following code, hope it will work for you as well. 我可以使用以下代码解决扩展/折叠所有问题,希望它也对您有用。
function expand(id) {
var o = $.extend({}, $.fn.accordion.defaults, null);
var containerID = o.container ? id : '', objID = o.objID ? o.objID : o.obj + o.objClass, Obj = o.container ? containerID + ' ' + objID : id, El = Obj + ' ' + o.el, hTimeout = null;
$(El + ' a.trigger').closest(o.wrapper).find('> ' + o.next).show().closest(o.wrapper).find('a.trigger').addClass('open').data('state', 1);
}
function collapse(id) {
var o = $.extend({}, $.fn.accordion.defaults, null);
var containerID = o.container ? id : '', objID = o.objID ? o.objID : o.obj + o.objClass, Obj = o.container ? containerID + ' ' + objID : id, El = Obj + ' ' + o.el, hTimeout = null;
$(El + ' a.trigger').closest(o.wrapper).find('> ' + o.next).not('.shown').hide().closest(o.wrapper).find('a.open').removeClass('open').data('state', 0);
}
Example:
expand('#accordion1');
collapse('#accordion1');
I'm faced with the exact same problem and would like to know if you ever found an answer? 我面临着完全相同的问题,想知道您是否找到答案了吗?
The work around I plan to use is something like $('.accordion a').click(); 我计划使用的解决方法类似于$('。accordion a')。click();。 to programmatically click each link in the list - not pretty but it seems to work...
以编程方式单击列表中的每个链接-不太漂亮,但似乎可以使用...
Two years later and I have the same desire... use Adi Palaz nested accordion, but have my OWN styled and specific action expand/collapse all buttons. 两年后,我有同样的愿望...使用Adi Palaz嵌套手风琴,但要用我自己的OWN风格和特定的动作来扩展/折叠所有按钮。 I did finally get it to work the way I wanted even though I am admittedly a novice level jquery programmer.
即使我确实是菜鸟级的jquery程序员,我也终于按照我想要的方式工作了。 Here's my key learnings:
这是我的主要知识:
$("#acc1").accordion({ obj: "div", el: ".h", head: "h4, h5", next: "div", iconTrigger: true });
<a href="#" class="ExpandAll">[Expand All]</a> <a href="#" class="CollapseAll">[Collapse All]</a>
$(Obj).delegate('a.CollapseAll', ev, function(ev) { $( o.obj + o.objClass ).find('a.trigger').each(function() { var $thislink = $(this), $thisWrapper = $thislink.closest(o.wrapper), $nextEl = $thisWrapper.find('> ' + o.next); if (($nextEl).length && $thislink.data('state') && (o.collapsible)) { $thislink.removeClass('open'); $nextEl.filter(':visible')[o.hideMethod](o.hideSpeed, function() {$thislink.data('state', 0);}); } }); });
I know this could likely be much more efficient, but I am thrilled to at least have it working given my skill level! 我知道这可能会更有效率,但是我很高兴至少在我的技能水平下可以正常工作!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.