スライダーで同様の構造を使用する場合、
JS
var active = 0;
$('.btn').click(function() {
var $btn = $(this);
var $box = $('#area-wrap').find('.box');
$box.eq(active).slideUp(function() {
if ($btn.hasClass('next')) {
if (active == $box.length - 1) {
active = 0;
}
else {
active ++;
}
}
else {
if (active == 0) {
active = $box.length - 1;
}
else {
active --;
}
}
$box.eq(active).delay(500).slideDown();
});
});
マークアップ:
<div id="area-wrap">
<!-- First Panel (Start) -->
<div class='box'>
<div class="left-panel1">1st Panels</div>
<div class="right-panel1">1st Panels</div>
</div>
<!-- Second Panel (Hidden) -->
<div class='box hidden'>
<div class="left-panel2">2nd Panels</div>
<div class="right-panel2">2nd Panels</div>
</div>
<!-- Third Panel (Hidden) -->
<div class='box hidden'>
<div class="left-panel3" >3rd Panels</div>
<div class="right-panel3">3rd Panels</div>
</div>
<div style="clear:both"></div>
<div class="btn next">NEXT</div>
<div class="btn prev">PREV</div>
</div>
と追加
.hidden{
display:none;
}
CSSに。
デモ