Accordion Effects by Script.aculo.us
- Date
- 2006-04-05 (Wed)
- Category
- javascript
Demo
- Try
- Accordion Effect.
Download
- download:
- Accordion 1.0
- license:
- MIT License, same as script.aculo.us
What is this?
On Rico site, it shows as Accordion Exmple, and you can see the top page of Moo.fx (it's called fx.Accordion in their Documentation page) as well. I made a similar effect only with Script.aculo.us. You can try its working demo from the link on the top. In short, this is a way to show several panels, which you can only see ONE panel at one time, and choose the one you see by clicking on it.
There is an implementaion on Wiki of Script.aculo.us, but it seems like no scalability at all (put unique id on each panel? NO WAY!), I made by myself for my purpose.
How to use it?
Of course, you need to have prototype.js and scriptaculous.js(?load=effects). After loading these two, you can do like..
<script type="text/javascript" src="accordion.js"></script>
in order to load the script.
And then, here is an example of Accordion-behavior HTML elements.
<div id="accordion">
<div class="panel">
<h3>Item 1</h3>
<div class="panelBody">
<p>Something something.</p>
</div>
</div>
<div class="panel">
....
</div>
Here comes a list of spec.
- “Accordion” must be marked-up by a Block element with unique ID.
- Each panel must be marked-up by a Block element with class name of “panel”
- Each panel must have a heading element (doesn' have to be HTML's HEADING element, such as H1, H2.. in terms of meaningful mark-up, it is strongly recommended though)
- Each panel must have a body element, and be given a class name of “panelBody”.
Finally, you can instantiate the class, like following.
var acc = new Accordion("accordion", "h3", "acc");
Accrodion class (basically) accepts 3 arguments.
- Id name of entire Accordion elements
- Tag name of each panel's heading element
- Instance name (technically, it is just a variable name in global context, which points to Accordion Object )
Other
You can actually change the class name of Panel Element (“panel” as default) and Panel Body Element (“panelBody” as default). When you instantiate Accordion Object, you can put customized a class name of Panel Element as a fourth argument, and Panel Body Element as a fifth.
Enjoy!!
Comment:6
- Daniel:2006-04-26 (Wed) 13:13
-
Wow! This is great, thanks for sharing with all of us!
- el_vartauy:2007-07-03 (Tue) 12:12
-
hello, what about more flexible class definitions.
if (Element.hasClassName(tags.item(i), this.headingClassName))
instead of:
if (tags.item(i).className == this.headingClassName)
good job and luck.
- Antonie Potgieter:2007-07-14 (Sat) 03:52
-
Thank you for this great accordation class! I was looking for this all day long. Thanks again.
- Emiliano:2007-07-19 (Thu) 17:09
-
Great accordation class!!!! But is it possible to make that the panels stay opened? in order to have more than one open panel?
thanks!!
- Dav:2007-08-07 (Tue) 11:10
-
Hello!!! GREAT SCRIPT, thanks a lot.
But please could you help me to use it with nested accordions? Because the problem is that parent div does not increase the height when opening child one.
Any proposal or help? thank you in advance
- tksh:2007-08-08 (Wed) 14:25
-
So, everybody.. Thanks for you comments.
> el_vartauy
I agree with you. That's better.> Emiliano
I think it's out of my original scope. Accordion style is good only when a user needs to concentrate one pane, and do step by step. I have never seen a good moving (or reshaping) interface before. Collapsing/expanding motion is just an eye candy, the nature of Accordion style is, again, to keep user's focus in one single pane.
> Dav
Nested accordion.. might be a good idea.
Again, this code is MIT License, feel free to change it and if you make something good, trackback me then.I may change this sometimes, but may not be soon.
Trackback:0
- TrackBack URL for this entry
- http://blogs.grf-design.com/mt/mt-tb.cgi/163
- Listed below are links to weblogs that reference
- Accordion Effects by Script.aculo.us from The Croton