how can you prevent the user to drag the element outside the window?
elm.css({
top : $(window).scrollTop() + ($(window).height() - elm.height()) / 2+'px',
left : ($(window).width() - elm.width()) / 2+'px'
})
.draggable({
handle : tr_top
});
Limit draggable area using 'containment' option It is simple. All you have to do is, add an option called containment to the draggable() method. The containment option has a value parent.
You have one of these problems: Your jQuery or jQuery UI Javascript path files are wrong. Your jQuery UI does not include draggable. Your jQuery or jQuery UI Javascript files are corrupted.
You can use the containment option:
elm.draggable({
handle: tr_top,
containment: "window"
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With