Skip to content

Commit a1b32b5

Browse files
committed
Resizable: use css() instead of position() for absolute placement. Fixes #3815 - Resizable: absolutely positioned element inside scrollable element is repositioned when resized
1 parent 9eaa572 commit a1b32b5

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

tests/unit/resizable/resizable_core.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,33 @@ test("handle with complex markup (#8756)", function() {
162162
);
163163

164164
var handle = '.ui-resizable-w div', target = $('#resizable1').resizable({ handles: 'all' });
165-
165+
166166
TestHelpers.resizable.drag(handle, -50);
167167
equal( target.width(), 150, "compare width" );
168168

169169
TestHelpers.resizable.drag(handle, 50);
170170
equal( target.width(), 100, "compare width" );
171171
});
172172

173+
test("resizable accounts for scroll position correctly (#3815)", function() {
174+
expect( 3 );
175+
176+
var position, top, left,
177+
container = $("<div style='overflow:scroll;height:300px;width:300px;position:relative;'></div>").appendTo("#qunit-fixture"),
178+
overflowed = $("<div style='width: 1000px; height: 1000px;'></div>").appendTo( container ),
179+
el = $("<div style='height:100px;width:100px;position:absolute;top:10px;left:10px;'></div>").appendTo( overflowed ).resizable({ handles: 'all' }),
180+
handle = ".ui-resizable-e";
181+
182+
container.scrollLeft( 100 ).scrollTop( 100 );
183+
184+
position = el.position();
185+
left = el.css("left");
186+
top = el.css("top");
187+
188+
TestHelpers.resizable.drag(handle, 50, 50);
189+
deepEqual( el.position(), position, "position stays the same when resized" );
190+
equal( el.css("left"), left, "css('left') stays the same when resized" );
191+
equal( el.css("top"), top, "css('top') stays the same when resized" );
192+
});
193+
173194
})(jQuery);

ui/jquery.ui.resizable.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,11 @@ $.widget("ui.resizable", $.ui.mouse, {
266266
el = this.element;
267267

268268
this.resizing = true;
269-
this.documentScroll = { top: $(document).scrollTop(), left: $(document).scrollLeft() };
270269

271270
// bugfix for http://dev.jquery.com/ticket/1749
272-
if (el.is('.ui-draggable') || (/absolute/).test(el.css('position'))) {
271+
if ( (/absolute/).test( el.css('position') ) ) {
272+
el.css({ position: 'absolute', top: el.css('top'), left: el.css('left') });
273+
} else if (el.is('.ui-draggable')) {
273274
el.css({ position: 'absolute', top: iniPos.top, left: iniPos.left });
274275
}
275276

0 commit comments

Comments
 (0)