Skip to content

Commit df7e32f

Browse files
committed
Draggable: Check all parents for fixed positioning when scrolling
Fixes #9612
1 parent 95546c5 commit df7e32f

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

tests/unit/draggable/draggable_core.js

+20-12
Original file line numberDiff line numberDiff line change
@@ -182,25 +182,33 @@ test( "#9315: jumps down with offset of scrollbar", function() {
182182
});
183183
});
184184

185-
test( "#5009: scroll not working with parent's position fixed", function() {
185+
test( "scroll offset with fixed ancestors", function() {
186186
expect( 2 );
187187

188188
var startValue = 300,
189-
element = $( "#draggable1" ).wrap( "<div id='wrapper' />" ).draggable({
190-
drag: function() {
191-
startValue += 100;
192-
$( document ).scrollTop( startValue ).scrollLeft( startValue );
193-
},
194-
stop: function( event, ui ) {
195-
equal( ui.position.left, 10, "left position is correct when parent position is fixed" );
196-
equal( ui.position.top, 10, "top position is correct when parent position is fixed" );
197-
$( document ).scrollTop( 0 ).scrollLeft( 0 );
198-
}
199-
});
189+
element = $( "#draggable1" )
190+
// http://bugs.jqueryui.com/ticket/5009
191+
// scroll not working with parent's position fixed
192+
.wrap( "<div id='wrapper' />" )
193+
// http://bugs.jqueryui.com/ticket/9612
194+
// abspos elements inside of fixed elements moving away from the mouse when scrolling
195+
.wrap( "<div id='wrapper2' />" )
196+
.draggable({
197+
drag: function() {
198+
startValue += 100;
199+
$( document ).scrollTop( startValue ).scrollLeft( startValue );
200+
},
201+
stop: function( event, ui ) {
202+
equal( ui.position.left, 10, "left position is correct when parent position is fixed" );
203+
equal( ui.position.top, 10, "top position is correct when parent position is fixed" );
204+
$( document ).scrollTop( 0 ).scrollLeft( 0 );
205+
}
206+
});
200207

201208
TestHelpers.forceScrollableWindow();
202209

203210
$( "#wrapper" ).css( "position", "fixed" );
211+
$( "#wrapper2" ).css( "position", "absolute" );
204212

205213
element.simulate( "drag", {
206214
dx: 10,

ui/draggable.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ $.widget("ui.draggable", $.ui.mouse, {
174174
this.cssPosition = this.helper.css( "position" );
175175
this.scrollParent = this.helper.scrollParent( true );
176176
this.offsetParent = this.helper.offsetParent();
177-
this.offsetParentCssPosition = this.offsetParent.css( "position" );
177+
this.hasFixedAncestor = this.helper.parents().filter(function() {
178+
return $( this ).css( "position" ) === "fixed";
179+
}).length > 0;
178180

179181
//The element's absolute position on the page minus margins
180182
this.positionAbs = this.element.offset();
@@ -236,7 +238,7 @@ $.widget("ui.draggable", $.ui.mouse, {
236238

237239
_mouseDrag: function(event, noPropagation) {
238240
// reset any necessary cached properties (see #5009)
239-
if ( this.offsetParentCssPosition === "fixed" ) {
241+
if ( this.hasFixedAncestor ) {
240242
this.offset.parent = this._getParentOffset();
241243
}
242244

0 commit comments

Comments
 (0)