実験的に開発した小さなプログラムやWebサービスを公開。また、気になった最新IT技術情報をブログ形式でメモ。
Accordion v1.0 伸縮するアコーディオンJSライブラリ
Accordion v1.0
伸縮するアコーディオンJSライブラリ「Accordion v1.0」です。
prototype.jsとscript.aculo.usのeffect.jsをベースとなっており、簡単に実装できます。
また、縦向きも横向きも出来てなかなかカッコいい。
実装方法は以下
[ファイルのインクルード]
- <script src="javascript/prototype.js" type="text/javascript"></script>
- <script src="javascript/effects.js" type="text/javascript"></script>
- <script src="javascript/accordion.js" type="text/javascript"></script>
[htmlの用意]
Title Bar
…
…
…
…
Title Bar
…
基本的にこれだけですが、オプションで以下が設定できます。
- // The speed of the accordion
- resizeSpeed : 8,
- // The classnames to look for
- classNames : {
- // The standard class for the title bar
- toggle : 'accordion_toggle',
- // The class used for the active state of the title bar
- toggleActive : 'accordion_toggle_active',
- // The class used to find the content
- content : 'accordion_content'
- },
- // If you don't want the accordion to stretch to fit
- // its content, set a value here, handy for horixontal examples.
- defaultSize : {
- height : null,
- width : null
- },
- // The direction of the accordion
- direction : 'vertical',
- // Should the accordion activate on click or say on mouseover? (apple.com)
- onEvent : 'click'
また、横向きの伸縮も可能です。
- // General Syntax
- new accordion('container-selector', options);
// Horizontal example
var horizontalAccordion = new accordion(’#top_container’, {
classNames : {
toggle : ‘horizontal_accordion_toggle’,
toggleActive : ‘horizontal_accordion_toggle_active’,
content : ‘horizontal_accordion_content’
},
defaultSize : {
width : 525
},
direction : ‘horizontal’
});
// Vertical Accordion
var verticalAccordion = new accordion(’#bottom_container’);
最後にonLoad時などにスライドを開きたいときは
- // Let's create it
- var verticalAccordion = new accordion('#bottom_container');
// Now lets open the first slide
verticalAccordion.activate($$(’#bottom_container .accordion_toggle’)[0]);

RSS Feed