<div id="accordion">
<div class="panel_container" id="panel1">
<h3>Panel 1</h3>
<div id="panel1-body" class="panel_body">
<div>
This is the contents of this panel.
</div>
</div>
</div>
<div class="panel_container" id="panel2">
<h3>Panel 2</h3>
<div id="panel2-body" class="panel_body">
<div>
This is the contents of this panel.
</div>
</div>
</div>
<div class="panel_container" id="panel3">
<h3>Panel 3</h3>
<div id="panel3-body" class="panel_body">
<div>
This is the contents of this panel.
</div>
</div>
</div>
<div class="panel_container" id="panel4">
<h3>Panel 4</h3>
<div id="panel4-body" class="panel_body">
<div>
This is the contents of this panel.
</div>
</div>
</div>
<div class="panel_container" id="panel5">
<h3>Panel 5</h3>
<div id="panel5-body" class="panel_body">
<div>
This is the contents of this panel.
</div>
</div>
</div>
</div>
var sliding = 0;
var slideTime = '';
var panelHeight = 150;
var effectDuration = 300;
var idleTime = 10000;
// Set is sliding value
function setSliding(a_ISliding){
sliding = a_ISliding;
}
// Get is sliding value
function getSliding(){
return sliding;
}
// Carry out accordian styled effect
function accordion() {
var eldown = this.getNext();
// If element is visible do nothing
if ($('visible') == this) {
return false;
}
if ($('visible')) {
if( getSliding() == 1 ){
return false;
}
var elup = $('visible').getNext();
setSliding( 1 );
parellelSlide( elup, eldown );
$('visible').id = '';
}
else{
setSliding( 1 );
singleSlide( eldown );
}
this.id = 'visible';
}
function getElementsByClassNameFix(tag, className) {
// This method of populating is used as Safari does use getElementsByClassName()
var elements = [];
var safariElements = $A(document.getElementsByTagName(tag));
safariElements.each(function(safariElements){
if(!safariElements.className.match(className)) return;
elements.push(safariElements);
});
return elements;
}
// Setup accordian initial state
function init() {
var bodyPanels = getElementsByClassNameFix('div', 'panel_body');
var panels = getElementsByClassNameFix('div', 'panel_container');
var noPanels = panels.length;
var percentageWidth = 100 / noPanels;
var position = 0;
// Loop through body panels and panels applying required styles and adding event listeners
for (i = 0; i < bodyPanels.length; i++) {
bodyPanels[i].style.height = '0px';
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.