If I have 2 <divs>, a and b that are separate divs that are absolute positioned. If I drag DIV B, can move anywhere. If I drag A, then DIV B will move by the same offset as that moved by div A.
What I know so far is this, however, despite being able to place div B anywhere I want. Upon moving div A, div B just snaps back to the place next to div A..
$('.a, .b').draggable({
drag: function(event, ui) {
$('.a').css({
top: ui.offset.top + 'px',
left: ui.offset.left + 100 + 'px'
});
}
});
Is there a way I can add some kind of “mouseoffset” to make this work?
Try this:
Working jsfiddle demo: http://jsfiddle.net/dkJFh/1/
It basically saves the start position of B on every mousemove so it can calculate the offset next time.