Skip to content

Commit 49c7b72

Browse files
committed
Draggable: Don't cache parent offset if the parent position is fixed. Fixes #5009 - Draggable: scroll not working with parent's position fixed
1 parent a88d645 commit 49c7b72

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

tests/unit/draggable/draggable_core.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,34 @@ test( "#6258: not following mouse when scrolled and using overflow-y: scroll", f
129129
});
130130
});
131131

132+
test( "#5009: scroll not working with parent's position fixed", function() {
133+
expect( 2 );
134+
135+
var startValue = 300,
136+
element = $( "#draggable1" ).wrap( "<div id='wrapper' />" ).draggable({
137+
drag: function() {
138+
startValue += 100;
139+
$( document ).scrollTop( startValue ).scrollLeft( startValue );
140+
},
141+
stop: function( event, ui ) {
142+
equal( ui.position.left, 10, "left position is correct despite overflow on HTML" );
143+
equal( ui.position.top, 10, "top position is correct despite overflow on HTML" );
144+
$( document ).scrollTop( 0 ).scrollLeft( 0 );
145+
}
146+
}),
147+
contentToForceScroll = $( "<div>" ).css({
148+
height: "20000px",
149+
width: "20000px"
150+
});
151+
152+
$( "#qunit-fixture" ).append( contentToForceScroll );
153+
$( "#wrapper" ).css( "position", "fixed" );
154+
155+
element.simulate( "drag", {
156+
dx: 10,
157+
dy: 10,
158+
moves: 3
159+
});
160+
});
161+
132162
})( jQuery );

ui/jquery.ui.draggable.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,10 @@ $.widget("ui.draggable", $.ui.mouse, {
125125
this._cacheMargins();
126126

127127
//Store the helper's css position
128-
this.cssPosition = this.helper.css("position");
128+
this.cssPosition = this.helper.css( "position" );
129129
this.scrollParent = this.helper.scrollParent();
130+
this.offsetParent = this.helper.offsetParent();
131+
this.offsetParentCssPosition = this.offsetParent.css( "position" );
130132

131133
//The element's absolute position on the page minus margins
132134
this.offset = this.positionAbs = this.element.offset();
@@ -184,6 +186,10 @@ $.widget("ui.draggable", $.ui.mouse, {
184186
},
185187

186188
_mouseDrag: function(event, noPropagation) {
189+
// reset any necessary cached properties (see #5009)
190+
if ( this.offsetParentCssPosition === "fixed" ) {
191+
this.offset.parent = this._getParentOffset();
192+
}
187193

188194
//Compute the helpers position
189195
this.position = this._generatePosition(event);
@@ -320,7 +326,6 @@ $.widget("ui.draggable", $.ui.mouse, {
320326
_getParentOffset: function() {
321327

322328
//Get the offsetParent and cache its position
323-
this.offsetParent = this.helper.offsetParent();
324329
var po = this.offsetParent.offset();
325330

326331
// This is a special case where we need to modify a offset calculated on start, since the following happened:

0 commit comments

Comments
 (0)