Opened 6 years ago

Closed 3 years ago

Last modified 3 years ago

#6884 closed bug (fixed)

Draggable: ui.offset.left differs between the "start" and "drag" hooks

Reported by: traviscooper Owned by:
Priority: minor Milestone: 1.11.2
Component: ui.draggable Version: 1.8.8
Keywords: Cc:
Blocked by: Blocking:

Description

when using the 'ui.offset.left' value with the start, drag and stop events for DRAGGABLE, you get a different value range for the start event versus the drag and stop.

For example, the following output was generated by asking for the 'ui.position.left' and ui.offset.left' for each of the events listed (start, drag, stop), as I dragged the element 1px to the right.

Notice how on the [start] event, the ui.offset.left (ui.o.l value) is "645", but for the [drag] and [start] events, the values become exactly what the ui.position.left values are (ui.p.l).

[start]--ui.p.l(247)ui.o.l(645) [drag]--ui.p.l(248)ui.o.l(248) [stop]--ui.p.l(248)ui.o.l(248)

From my own calculations, the above output SHOULD be.

[start]--ui.p.l(247)ui.o.l(645) [drag]--ui.p.l(248)ui.o.l(646) [stop]--ui.p.l(248)ui.o.l(646)

Below is my code to reproduce.

$('.element_to_move').draggable({

containment: 'parent', cursor: 'pointer', scroll: true, axis: 'x' , grid: [1,0], start: function(event, ui) {

Update element data in Display $('#er2').append('[start]--ui.p.l('+ui.position.left+')ui.o.l('+ui.offset.left+')<br />');

}, drag: function(event, ui) {

Update element data in Display $('#er2').append('[drag]--ui.p.l('+ui.position.left+')ui.o.l('+ui.offset.left+')<br />');

}, stop: function(event, ui){

Update element data in Display $('#er2').append('[stop]--ui.p.l('+ui.position.left+')ui.o.l('+ui.offset.left+')<br />');

}

});

Change History (7)

comment:1 Changed 6 years ago by traviscooper

I'm thinking it shouldn't matter what the CSS positioning value is for the parent or element, since the initial value of the 'ui.offset.left' is correct.

comment:2 Changed 6 years ago by traviscooper

Here is the jsbin working demo of the error.

http://jsbin.com/ilike4

comment:3 Changed 4 years ago by scottgonzalez

  • Milestone changed from 1.9.0 to 2.0.0

comment:4 Changed 4 years ago by mikesherov

  • Status changed from new to open

New demo using latest: http://jsfiddle.net/48uVM/1/ which confirms the discrepancy. It looks to be on purpose and part of the internals: https://github.com/jquery/jquery-ui/blob/039ee746d3eaeeaa4ad92ecd8ebf4e6fcd11768c/ui/jquery.ui.draggable.js#L426

However, this is not ideal, and if the internals need to rely on the "position" values provided, they should be named appropriately to signify they aren't equivalent to the common notion of position and offset.

comment:5 Changed 4 years ago by mikesherov

  • Summary changed from ui.offset.left not correct values to Draggable: ui.offset.left differs between the "start" and "drag" hooks

comment:6 Changed 3 years ago by Mike Sherov

  • Resolution set to fixed
  • Status changed from open to closed

Draggable: Recalculate hash offset on start after plugins run

Fixes #6884 Changeset: b5846bece34db31d69e75cb3a3537827c005910e

comment:7 Changed 3 years ago by mikesherov

  • Milestone changed from 2.0.0 to 1.11.2

Better late than never!

Note: See TracTickets for help on using tickets.