Skip to content

Commit 4a5a21c

Browse files
committed
fix horizontal accordion animation problems
1 parent e4995ac commit 4a5a21c

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

src/tabs/tabs.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,24 @@
9494

9595
$.tools.tabs.addEffect("horizontal", function(i, done) {
9696

97+
var nextPane = this.getPanes().eq(i);
98+
9799
// store original width of a pane into memory
98100
w || ( w = this.getPanes().eq(0).width() );
99101

100-
// set current pane's width to zero
101-
this.getCurrentPane().animate({width: 0}, function(){
102-
$(this).hide();
103-
});
104-
105-
// grow opened pane to it's original width
106-
this.getPanes().eq(i).animate({width: w}, function() {
107-
$(this).show();
108-
done.call();
109-
});
102+
nextPane.show(); // hidden by default
110103

104+
// set current pane's width to zero
105+
// animate next pane at the same time for smooth animation
106+
this.getCurrentPane().animate({width: 0}, {
107+
step: function(now){
108+
nextPane.css("width", w-now);
109+
},
110+
complete: function(){
111+
$(this).hide();
112+
done.call();
113+
}
114+
});
111115
});
112116

113117

@@ -161,10 +165,10 @@
161165
// call the effect
162166
effects[conf.effect].call(self, i, function() {
163167

168+
current = i;
164169
// onClick callback
165170
e.type = "onClick";
166-
trigger.trigger(e, [i]);
167-
current = i;
171+
trigger.trigger(e, [i]);
168172
});
169173

170174
// default behaviour
@@ -254,6 +258,7 @@
254258

255259
} else {
256260
if (conf.initialIndex === 0 || conf.initialIndex > 0) {
261+
current = conf.initialIndex; // ensure that current is set properly
257262
self.click(conf.initialIndex);
258263
}
259264
}

test/tabs/accordion-horizontal.htm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<!-- accordion header #1 -->
1010
<div class="blok"></div>
1111

12-
<div class="pane" style="width:200px; display:block">
12+
<div class="pane 0" style="width:200px; display:block">
1313
<h3>First pane</h3>
1414
<p>
1515
Consectetur adipiscing elit. Praesent bibendum eros ac nulla. Integer vel lacus ac neque viverra.
@@ -18,7 +18,7 @@ <h3>First pane</h3>
1818

1919
<div class="blok"></div>
2020

21-
<div class="pane">
21+
<div class="pane 1">
2222
<h3>Second pane</h3>
2323
<p>
2424
Cras diam. Donec dolor lacus, vestibulum at, varius in, mollis id, dolor. Aliquam erat volutpat.
@@ -27,7 +27,7 @@ <h3>Second pane</h3>
2727

2828
<div class="blok"></div>
2929

30-
<div class="pane">
30+
<div class="pane 2">
3131
<h3>Third pane</h3>
3232
<p>
3333
Non lectus lacinia egestas. Nulla hendrerit, felis quis elementum viverra, purus felis egestas magna.

test/tabs/css/horizontal.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
float:left;
2828
display:none;
2929
margin-right:10px;
30+
overflow:hidden;
3031
}
3132

3233
/* content inside a pane should have fixed width */

0 commit comments

Comments
 (0)