Nathan30
Nathan30

Reputation: 871

jQuery draggable out of window

I'm using jQuery UI for a personnal project and I want to know something. Is it possible to control the draggable jQuery item, in order to disable the possibility to get the draggable item out of the window ?

I'm not sure if I'm clear enough, so here is a screen of what I don't want to have : Link

Thanks in advance !

Upvotes: 0

Views: 2156

Answers (1)

Sorangwala Abbasali
Sorangwala Abbasali

Reputation: 827

When you use jQuery UI Draggable, you have an option called Containment. In that, you can specify the parent, inside which it should be constrained. In your case, the parent should be the body.

You can use this initiation function:

$( "#yourElement" ).draggable({ scroll: false });

You can also use the following:

$("#element").draggable({
    handle: tr_top,
    containment: "window"
});

Upvotes: 1

Related Questions