Skip to content

Commit c726c4a

Browse files
hrosenbauervieron
authored andcommitted
fix(draggable): fix offset during drag
when the scrollX/Y is changed during drag (e.g. by the mousewheel) the offset wasn't correct
1 parent 93c46ff commit c726c4a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/jquery.draggable.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@
131131
var diff_y = Math.round(mouse_actual_pos.top - this.mouse_init_pos.top);
132132

133133
var left = Math.round(this.el_init_offset.left +
134-
diff_x - this.baseX + this.scroll_offset_x);
134+
diff_x - this.baseX + window.scrollX - this.win_offset_x);
135135
var top = Math.round(this.el_init_offset.top +
136-
diff_y - this.baseY + this.scroll_offset_y);
136+
diff_y - this.baseY + window.scrollY - this.win_offset_y);
137137

138138
if (this.options.limit) {
139139
if (left > this.player_max_left) {
@@ -151,8 +151,8 @@
151151
pointer: {
152152
left: mouse_actual_pos.left,
153153
top: mouse_actual_pos.top,
154-
diff_left: diff_x + this.scroll_offset_x,
155-
diff_top: diff_y + this.scroll_offset_y
154+
diff_left: diff_x + (window.scrollX - this.win_offset_x),
155+
diff_top: diff_y + (window.scrollY - this.win_offset_y)
156156
}
157157
};
158158
};
@@ -299,6 +299,8 @@
299299
this.helper = false;
300300
}
301301

302+
this.win_offset_y = window.scrollY;
303+
this.win_offset_x = window.scrollX;
302304
this.scroll_offset_y = 0;
303305
this.scroll_offset_x = 0;
304306
this.el_init_offset = this.$player.offset();

0 commit comments

Comments
 (0)