Reputation: 5234
I have a modal with dragging functionality. It works fine, but when I close and reopen the modal it retains its last position. For example, if I drag the modal to the bottom of the window and close it, when I reopen the modal it's at the bottom of the window. I need it to be centered as it was the first time it was launched. I am using JQuery UI
and Bootstrap
here.
Here's my code:
<div class="outerContainer">
....
....
<!-- Modal -->
<div class="modal fade" id="alertModal" tabindex="-1" role="dialog" aria-labelledby="alertModalLabel" aria-hidden="true">
<div class="modal-dialog" id="contentModal">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="alertModalLabel">Add Alert</h4>
</div>
<div class="modal-body">
<div class="container-fluid">
@Html.Partial("~/Views/Shared/Maintenance/_AddAlert.cshtml", Model.AlertViewModel);
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
<script>
$(function () {
$("#alertModal").draggable({
handle: ".modal-header",
scroll: false,
containment: '#outerContainer'
});
});
</script>
Upvotes: 0
Views: 1474
Reputation: 331
When you close/open it you can hook into the modal events and re-position accordingly:
$('#alertModal').on('hidden.bs.modal', function (e) {
// reposition modal according to window / viewport here
});
See bootstrap docs where it talks about hooking into events.
HTH
Upvotes: 1