aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgnarf <gnarf@gnarf.net>2011-06-13 13:02:16 -0500
committergnarf <gnarf@gnarf.net>2011-06-14 15:10:54 -0500
commitc1f71f1c2f732e58a8fbca91185a284ea8db6b1b (patch)
treebe3663bba7830957326c917589f3163f029b2ffe
parentb0182d78229058fdf61d5f9c3b8a66617d056f30 (diff)
downloadjquery-ui-c1f71f1c2f732e58a8fbca91185a284ea8db6b1b.tar.gz
jquery-ui-c1f71f1c2f732e58a8fbca91185a284ea8db6b1b.zip
Effects.scale: Update the position of the element post animation to avoid jumping - Fixed #4316 - Element jumps to wrong position after scale effect with origin: ['middle','center'] parameter
-rw-r--r--ui/jquery.effects.scale.js49
1 files changed, 46 insertions, 3 deletions
diff --git a/ui/jquery.effects.scale.js b/ui/jquery.effects.scale.js
index fe0c03c53..e00d82497 100644
--- a/ui/jquery.effects.scale.js
+++ b/ui/jquery.effects.scale.js
@@ -118,8 +118,11 @@ $.effects.effect.size = function( o ) {
mode = $.effects.setMode( el, o.mode || 'effect' ),
restore = o.restore || mode !== "effect",
scale = o.scale || 'both',
- origin = o.origin,
- original, baseline, factor;
+ origin = o.origin || [ "middle", "center" ],
+ original, baseline, factor,
+ position = el.css( "position" ),
+ originalVerticalPositioning = el.css( "bottom" ) !== "auto" ? "bottom" : "top";
+ originalHorizontalPositioning = el.css( "right" ) !== "auto" ? "right" : "left";
if ( mode === "show" ) {
el.show();
@@ -249,7 +252,47 @@ $.effects.effect.size = function( o ) {
if( mode == 'hide' ) {
el.hide();
}
- $.effects.restore( el, restore ? props : props1 );
+ $.effects.restore( el, restore ? props : props1 );
+
+ // we need to recalculate our positioning based on the new scaling
+ if ( position === "static" ) {
+ el.css({
+ position: "relative",
+ top: el.to.top,
+ left: el.to.left
+ });
+ } else {
+ $.each([ originalVerticalPositioning, originalHorizontalPositioning ], function( idx, pos ) {
+ el.css( pos, function( _, str ) {
+ var val = parseInt( str, 10 ),
+ toRef = idx ? el.to.left : el.to.top,
+ delta = idx ? el.to.outerWidth - el.from.outerWidth: el.to.outerHeight - el.from.outerHeight,
+ same = origin[ idx ] === pos,
+ mid = origin[ idx ] === "middle" || origin[ idx ] === "center",
+ direction = pos == "left" || pos == "top";
+
+ // if original was "auto", recalculate the new value from wrapper
+ if ( str === "auto" ) {
+ return toRef + "px";
+ }
+
+ // if not setting left or top
+ if ( !direction ) {
+
+ // if the position is relative, bottom/right are reversed meaning
+ if ( position === "relative" ) {
+ toRef *= -1;
+
+ // otherwise, if its NOT a midpoint origin, compensate for the outerWidth difference
+ } else if ( !mid ) {
+ toRef -= delta * ( same ? -1 : 1 );
+ }
+ }
+ return val + toRef + "px";
+ });
+ });
+ }
+
$.effects.removeWrapper( el );
$.isFunction( o.complete ) && o.complete.apply( this, arguments ); // Callback
el.dequeue();