awps / accordion.js Goto Github PK
View Code? Open in Web Editor NEWAccordion.JS: Free jQuery Accordion plugin
Home Page: https://accordion.js.org
License: MIT License
Accordion.JS: Free jQuery Accordion plugin
Home Page: https://accordion.js.org
License: MIT License
It would be really helpful to have a bit in the docs which explains how to use this library to programmatically open/close sections. I have worked out a way to do it, but I'm not sure if there's a better way which the library expects.
Note, I've found that when you programmatically open a section, other open sections do not close, even if closeOther
is set to true
. (Not sure whether this is a bug, though.)
For the curious, here's my solution:
// Initialize the accordion
jQuery(document).ready(function($){
$("#my-accordion").accordionjs({
activeIndex : false,
openSection: myOpenAccordionSection,
});
and then later, close open sections and open another:
var newSection = $("#my-inner-content")[0].closest('.acc_section');
var acc = $('.accordionjs').accordionjs({activeIndex: false});
// Close all open sections which aren't the one that's been selected
acc.closeOtherSections($(newSection), 0);
// Open the selected section only if it isn't already
if (! $(newSection).hasClass('acc_active')) {
acc.openSection($(newSection), 0);
}
NB: You have to pass things like "activeIndex" again when you re-instantiate the accordion to call methods on it. The alternative, I guess, is to put them in the HTML as data-
attributes or to store the original variable instantiated in document.ready
.
And for those Googling, this will not work because you haven't called accordionjs()
on it:
var newSection = $('#my-inner-content')[0].closest('.acc_section');
$(".accordionjs").openSection($(newSection), 0);
This throws Uncaught TypeError: $(...).openSection is not a function
.
Is that plugin have any events and methods?
Hi,
Thanks for the develop this plugin.. It's really cool. I faced a issue when I used closeAble: true with nested accordion. Actually what happen was, nested accordion open and close when it click. How I fix this. Please help me.
Thanks!!
Is it possible in one of the accordion tabs e.g. section 1, to have a link that expands say section 3?
When we click on heading it scrolls to upward direction. Can we disable this?
Sample code/html exactly as per docs doesn't run:
Uncaught TypeError: t.slideDown is not a function
at w.fn.init.openSection (accordion.min.js:1)
at w.fn.init.create (accordion.min.js:1)
at i (accordion.min.js:1)
at w.fn.init.e.fn.accordionjs (accordion.min.js:1)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.