To remove containment from a draggable jQuery UI Dialog, try the following.
The trick is to use draggable's containtment property via widget of the dialog.
// Button that opens the dialog and a div to be used as the dialog <input type="button" id="btnOpenDialog" value="Open Dialog" /> <div id="dialog"></div>
<script type="text/javascript">
var myDialog = null; // global variable
$(function(){
$('#btnOpenDialog').on('click', function(){
// Step 1.
// Get the dialog ready.
myDialog = $('#dialog').dialog({
autoOpen: false, modal: true, resizable: true, width: 400,
buttons: {
OK: function(){ // perform some actions ...},
Cancel: function(){ $(this).dialog('close'); } // close the dialog
}
});
// Step 2.
// `myDialog` is a global variable and has a reference to the dialog.
// Use `myDialog` to remove containment from the dialog.
myDialog.dialog("widget").draggable({ containment: false });
// Step 3.
// Show the dialog
myDialog.dialog("open");
});
});
</script>
No comments:
Post a Comment