Skip to content

Commit d20f05e

Browse files
committed
Accordion: New approach to synchronizing animations. Fixes #4178 - Accordion animation a bit jumpy in some browsers.
1 parent 4ab4684 commit d20f05e

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

ui/jquery.ui.accordion.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,12 @@
1616

1717
var uid = 0,
1818
hideProps = {},
19-
showProps = {},
20-
showPropsAdjust = {};
19+
showProps = {};
2120

2221
hideProps.height = hideProps.paddingTop = hideProps.paddingBottom =
2322
hideProps.borderTopWidth = hideProps.borderBottomWidth = "hide";
2423
showProps.height = showProps.paddingTop = showProps.paddingBottom =
2524
showProps.borderTopWidth = showProps.borderBottomWidth = "show";
26-
$.extend( showPropsAdjust, showProps, { accordionHeight: "show" } );
27-
28-
$.fx.step.accordionHeight = function( fx ) {
29-
var elem = $( fx.elem ),
30-
data = elem.data( "ui-accordion-height" );
31-
elem.height( data.total - elem.outerHeight() - data.toHide.outerHeight() + elem.height() );
32-
};
3325

3426
$.widget( "ui.accordion", {
3527
version: "@VERSION",
@@ -485,12 +477,12 @@ $.widget( "ui.accordion", {
485477
_animate: function( toShow, toHide, data ) {
486478
var total, easing, duration,
487479
that = this,
480+
adjust = 0,
488481
down = toShow.length &&
489482
( !toHide.length || ( toShow.index() < toHide.index() ) ),
490483
animate = this.options.animate || {},
491484
options = down && animate.down || animate,
492485
complete = function() {
493-
toShow.removeData( "ui-accordion-height" );
494486
that._toggleComplete( data );
495487
};
496488

@@ -512,15 +504,29 @@ $.widget( "ui.accordion", {
512504
}
513505

514506
total = toShow.show().outerHeight();
515-
toHide.animate( hideProps, duration, easing );
507+
toHide.animate( hideProps, {
508+
duration: duration,
509+
easing: easing,
510+
step: function( now, fx ) {
511+
fx.now = Math.round( now );
512+
}
513+
});
516514
toShow
517515
.hide()
518-
.data( "ui-accordion-height", {
519-
total: total,
520-
toHide: toHide
521-
})
522-
.animate( this.options.heightStyle === "content" ? showProps : showPropsAdjust,
523-
duration, easing, complete );
516+
.animate( showProps, {
517+
duration: duration,
518+
easing: easing,
519+
complete: complete,
520+
step: function( now, fx ) {
521+
if ( fx.prop !== "height" ) {
522+
fx.now = Math.round( now );
523+
adjust += fx.now;
524+
} else {
525+
fx.now = Math.round( total - toHide.outerHeight() - adjust );
526+
adjust = 0;
527+
}
528+
}
529+
});
524530
},
525531

526532
_toggleComplete: function( data ) {

0 commit comments

Comments
 (0)