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
Detect if drag outside of parent using jQuery UI Draggable
Moderator: General Moderators
Re: Detect if drag outside of parent using jQuery UI Draggable
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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: Detect if drag outside of parent using jQuery UI Draggable
Thanks for the idea
I used the following code and it works
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) {
}
}