Ank*_*wal 3 html javascript css jquery twitter-bootstrap
我有一个引导模式,它调用另一个引导模式。现在的问题是,当我打开第二个引导模式并关闭它时,第一个引导模式不再滚动。相反,滚动是由后台主页获得的。我应该在这里做什么,以便当我关闭第二个模态时,第一个模态会聚焦并获得第二个模态之前的滚动。
$('#modalTrigger').on('click', function () {
setTimeout(function () {
$('#modalBody').html($('#contentText').html());
}, 1000);
});
$('#btnPrimaryModalAction').on('click', function () {
$('#secondaryModal').modal('show');
});
Run Code Online (Sandbox Code Playgroud)
这是JSFIDDLE的链接,其中包含定义上述情况的两个引导模式。
显示时的 Bootstrap 模态modal-open向您的<body>元素添加一个新类。当被关闭时,它会删除modal-open该类。
因此,您只需要<body>在关闭子模式时将该类重新应用于您的元素。事情是这样的:
为父模态内的模态添加一个新的自定义 css 类。
在我的情况,我用的.child-modal,
/* when using a modal within a modal, add this class on the child modal */
$(document).find('.child-modal').on('hidden.bs.modal', function () {
console.log('hiding child modal');
$('body').addClass('modal-open');
});
Run Code Online (Sandbox Code Playgroud)
html
<div class="modal fade" tabindex="-1" role="dialog">
...
<a href="#" data-toggle="modal" data-target="#other_modal" title="Help">
Open the other modal
</a>
...
</div>
<div class="modal fade child-modal" id="other_modal" tabindex="-1" role="dialog">
... other codes here ...
</div>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1994 次 |
| 最近记录: |