【问题标题】:JQuery UI Draggable ModaljQuery UI 可拖动模式
【发布时间】:2015-02-20 13:36:35
【问题描述】:

我有一个具有拖动功能的模式。它工作正常,但是当我关闭并重新打开模式时,它会保留其最后一个位置。例如,如果我将模态框拖到窗口底部并关闭它,当我重新打开模态框时,它位于窗口底部。我需要它居中,因为它是第一次启动。我在这里使用JQuery UIBootstrap

这是我的代码:

<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">&times;</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>

【问题讨论】:

标签: jquery asp.net-mvc twitter-bootstrap jquery-ui


【解决方案1】:

当您关闭/打开它时,您可以连接到模态事件并相应地重新定位:

$('#alertModal').on('hidden.bs.modal', function (e) {
    // reposition modal according to window / viewport here
});

请参阅bootstrap docs,其中谈到了挂钩事件。

HTH

【讨论】:

  • 这看起来很有希望,但我不知道如何在第一次加载模态时恢复原始位置。
  • 您不能真正存储初始位置并重新使用它(因为用户可以调整窗口大小) - 它必须是模态宽度与宽度相比的计算视点的宽度(screen.width()),类似的 WRT 高度,并相应地设置 left 和 top。
猜你喜欢
  • 2016-05-16
  • 2013-01-27
  • 2018-04-14
  • 2013-02-20
  • 2012-06-27
  • 2011-07-13
  • 2018-07-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多