Page 1 of 1
Detect if drag outside of parent using jQuery UI Draggable
Posted: Mon Apr 27, 2009 12:32 am
by cohq82
Hi, I am making a inner DIV to be draggable using jQuery UI Draggable. The inner DIV can only move horizonally and fit within the outer DIV (parent). I want to have some detection mechanism so that if the inner DIV moved further left or right of the outer DIV, I will show something (<< and >> arrow).
Is there any way to do this? Thanks
Re: Detect if drag outside of parent using jQuery UI Draggable
Posted: Mon Apr 27, 2009 10:07 am
by pickle
I think there's an event fired whenever the draggable element is dragged. Each time that event is called, I'd check the left/right edge of the inner div against the left/right edge of the outer div. If the inner div is left/right of the outer div, do something.
Re: Detect if drag outside of parent using jQuery UI Draggable
Posted: Mon Apr 27, 2009 11:39 pm
by cohq82
Thanks for the idea
I used the following code and it works
Code: Select all
stop: function(event, ui) {
if (ui.position.left>0) {
$(this).css('left', '0px');
}
if ($(this).right>0) {
}
}