Skip to content

Commit 2c81518

Browse files
tomykairagnarf
authored andcommitted
effects.core: Convert elements height/width to px and restore after animation in all effects. Fixed #5245 - Relative width elements break when wrapped for effects
1 parent 19dcac2 commit 2c81518

10 files changed

+48
-14
lines changed

tests/unit/effects/effects.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@
5454
.testChildren h2 {
5555
font-size: 20px;
5656
}
57+
58+
.relWidth {
59+
width: 50%;
60+
}
61+
62+
.relHeight {
63+
height: 50%;
64+
}
5765
</style>
5866
</head>
5967
<body>
@@ -70,6 +78,9 @@ <h2 id="qunit-userAgent"></h2>
7078
<div class="animateClass test">
7179
<h2>Child Element Test</h2>
7280
</div>
81+
<div class="relWidth relHeight testAddBorder">
82+
<h2>Slide with relative width</d2>
83+
</div>
7384
</div>
7485

7586
</body>

tests/unit/effects/effects_core.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ $.each( $.effects.effect, function( effect ) {
5454
start();
5555
}));
5656
});
57+
58+
asyncTest( "relative width & height - properties are preserved", function() {
59+
var test = $("div.relWidth.relHeight"),
60+
width = test.width(), height = test.height(),
61+
cssWidth = test[0].style.width, cssHeight = test[0].style.height;
62+
63+
expect( 4 );
64+
test.toggle( effect, minDuration, function() {
65+
equal( test[0].style.width, cssWidth, "Inline CSS Width has been reset after animation ended" );
66+
equal( test[0].style.height, cssHeight, "Inline CSS Height has been rest after animation ended" );
67+
start();
68+
});
69+
equal( test.width(), width, "Width is the same px after animation started" );
70+
equal( test.height(), height, "Height is the same px after animation started" );
71+
});
5772
});
5873

5974
module("animateClass");

ui/jquery.effects.blind.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ $.effects.effect.blind = function( o ) {
2121

2222
// Create element
2323
var el = $( this ),
24-
props = [ "position", "top", "bottom", "left", "right" ],
24+
props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
2525
mode = $.effects.setMode( el, o.mode || "hide" ),
2626
direction = o.direction || "up",
2727
vertical = rvertical.test( direction ),

ui/jquery.effects.bounce.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ $.effects.effect.bounce = function(o) {
1616

1717
return this.queue( function( next ) {
1818
var el = $( this ),
19-
props = [ "position", "top", "bottom", "left", "right" ],
19+
props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
2020

2121
// defaults:
2222
mode = $.effects.setMode( el, o.mode || "effect" ),

ui/jquery.effects.core.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,12 @@ $.extend( $.effects, {
410410
border: "none",
411411
margin: 0,
412412
padding: 0
413-
});
413+
}),
414+
// Store the size in case width/height are defined in % - Fixes #5245
415+
size = {
416+
width: element.width(),
417+
height: element.height()
418+
};
414419

415420
element.wrap( wrapper );
416421
wrapper = element.parent(); //Hotfix for jQuery 1.4 since some change in wrap() seems to actually loose the reference to the wrapped element
@@ -438,6 +443,7 @@ $.extend( $.effects, {
438443
bottom: "auto"
439444
});
440445
}
446+
element.css(size);
441447

442448
return wrapper.css( props ).show();
443449
},

ui/jquery.effects.drop.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ $.effects.effect.drop = function( o ) {
1717
return this.queue( function() {
1818

1919
var el = $( this ),
20-
props = [ 'position', 'top', 'bottom', 'left', 'right', 'opacity' ],
20+
props = [ 'position', 'top', 'bottom', 'left', 'right', 'opacity', "height", "width" ],
2121
mode = $.effects.setMode( el, o.mode || 'hide' ),
2222
direction = o.direction || 'left',
2323
ref = ( direction == 'up' || direction == 'down' ) ? 'top' : 'left',

ui/jquery.effects.fold.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $.effects.effect.fold = function( o ) {
1818

1919
// Create element
2020
var el = $( this ),
21-
props = ['position','top','bottom','left','right'],
21+
props = ['position','top','bottom','left','right','height','width'],
2222
mode = $.effects.setMode(el, o.mode || 'hide'),
2323
size = o.size || 15,
2424
percent = /([0-9]+)%/.exec(size),

ui/jquery.effects.scale.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ $.effects.effect.size = function( o ) {
116116

117117
// Set options
118118
mode = $.effects.setMode( el, o.mode || 'effect' ),
119-
restore = o.restore || false,
119+
restore = o.restore || mode !== "effect",
120120
scale = o.scale || 'both',
121121
origin = o.origin,
122122
original, baseline, factor;

ui/jquery.effects.shake.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ $.effects.effect.shake = function( o ) {
1717
return this.queue( function() {
1818

1919
var el = $( this ),
20-
props = [ "position", "top", "bottom", "left", "right" ],
20+
props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
2121
mode = $.effects.setMode( el, o.mode || "effect" ),
2222
direction = o.direction || "left",
2323
distance = o.distance || 20,

ui/jquery.effects.slide.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,26 @@ $.effects.effect.slide = function( o ) {
1818

1919
// Create element
2020
var el = $( this ),
21-
props = ['position','top','bottom','left','right'],
21+
props = [ "position", "top", "bottom", "left", "right", "width", "height" ],
2222
mode = $.effects.setMode( el, o.mode || 'show' ),
2323
direction = o.direction || 'left',
2424
ref = (direction == 'up' || direction == 'down') ? 'top' : 'left',
2525
motion = (direction == 'up' || direction == 'left') ? 'pos' : 'neg',
2626
distance,
27-
animation = {};
27+
animation = {},
28+
size;
2829

2930
// Adjust
30-
$.effects.save( el, props );
31+
$.effects.save( el, props );
3132
el.show();
33+
distance = o.distance || el[ ref == 'top' ? "outerHeight" : "outerWidth" ]({
34+
margin: true
35+
});
36+
3237
$.effects.createWrapper( el ).css({
3338
overflow: 'hidden'
34-
});
35-
36-
distance = o.distance || el[ ref == 'top' ? "outerHeight" : "outerWidth" ]({
37-
margin: true
3839
});
40+
3941
if (mode == 'show') {
4042
el.css( ref, motion == 'pos' ? (isNaN(distance) ? "-" + distance : -distance) : distance );
4143
}

0 commit comments

Comments
 (0)