RSS Feed

実験的に開発した小さなプログラムやWebサービスを公開。また、気になった最新IT技術情報をブログ形式でメモ。

Accordion v1.0 伸縮するアコーディオンJSライブラリ

Accordion v1.0
伸縮するアコーディオンJSライブラリ「Accordion v1.0」です。

prototype.jsとscript.aculo.usのeffect.jsをベースとなっており、簡単に実装できます。

また、縦向きも横向きも出来てなかなかカッコいい。

実装方法は以下

[ファイルのインクルード]

  1. <script src="javascript/prototype.js" type="text/javascript"></script>
  2. <script src="javascript/effects.js" type="text/javascript"></script>
  3. <script src="javascript/accordion.js" type="text/javascript"></script>

[htmlの用意]

Title Bar



Title Bar

基本的にこれだけですが、オプションで以下が設定できます。

  1. // The speed of the accordion
  2. resizeSpeed : 8,
  3. // The classnames to look for
  4. classNames : {
  5. // The standard class for the title bar
  6. toggle : 'accordion_toggle',
  7. // The class used for the active state of the title bar
  8. toggleActive : 'accordion_toggle_active',
  9. // The class used to find the content
  10. content : 'accordion_content'
  11. },
  12. // If you don't want the accordion to stretch to fit
  13. // its content, set a value here, handy for horixontal examples.
  14. defaultSize : {
  15. height : null,
  16. width : null
  17. },
  18. // The direction of the accordion
  19. direction : 'vertical',
  20. // Should the accordion activate on click or say on mouseover? (apple.com)
  21. onEvent : 'click'

また、横向きの伸縮も可能です。

  1. // General Syntax
  2. 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時などにスライドを開きたいときは

  1. // Let's create it
  2. var verticalAccordion = new accordion('#bottom_container');

// Now lets open the first slide
verticalAccordion.activate($$(’#bottom_container .accordion_toggle’)[0]);

関連記事

コメント