Accordion: Partial fix for #4011: Smooth(er) animations with autoHeight: false.

Removed some browser snifing.
Added support for non-px units.
This commit is contained in:
Scott González 2009-01-31 02:55:56 +00:00
parent 39dac81b24
commit 6695e5ac7f

View File

@ -395,14 +395,21 @@ $.extend($.ui.accordion, {
return; return;
} }
var overflow = options.toShow.css('overflow'), var overflow = options.toShow.css('overflow'),
percentDone,
showProps = {}, showProps = {},
hideProps = {}, hideProps = {},
fxAttrs = [ "height", "paddingTop", "paddingBottom" ]; fxAttrs = [ "height", "paddingTop", "paddingBottom" ];
$.each(fxAttrs, function(i, prop) { $.each(fxAttrs, function(i, prop) {
hideProps[prop] = 'hide'; hideProps[prop] = 'hide';
showProps[prop] = parseFloat(options.toShow.css(prop));
if (options.toShow[0]) {
var parts = ('' + $.css(options.toShow[0], prop)).match(/^([\d+-.]+)(.*)$/);
showProps[prop] = {
value: parts[1],
unit: parts[2] || 'px'
};
}
}); });
showProps.height = options.toShow.height();
options.toShow.css({ height: 0, overflow: 'hidden' }).show(); options.toShow.css({ height: 0, overflow: 'hidden' }).show();
options.toHide.filter(":hidden").each(options.complete).end().filter(":visible").animate(hideProps,{ options.toHide.filter(":hidden").each(options.complete).end().filter(":visible").animate(hideProps,{
step: function(now, settings) { step: function(now, settings) {
@ -410,14 +417,15 @@ $.extend($.ui.accordion, {
// a content pane to show // a content pane to show
if (!options.toShow[0]) { return; } if (!options.toShow[0]) { return; }
var percentDone = settings.start != settings.end // only calculate the percent when animating height
? (settings.now - settings.start) / (settings.end - settings.start) // IE gets very inconsistent results when animating elements
: 0, // with small values, which is common for padding
current = percentDone * showProps[settings.prop]; if (settings.prop == 'height') {
if ($.browser.msie || $.browser.opera) { percentDone = (settings.now - settings.start) / (settings.end - settings.start);
current = Math.ceil(current);
} }
options.toShow[0].style[settings.prop] = current + 'px';
options.toShow[0].style[settings.prop] =
(percentDone * showProps[settings.prop].value) + showProps[settings.prop].unit;
}, },
duration: options.duration, duration: options.duration,
easing: options.easing, easing: options.easing,