html - 从另一个模态创建模态时,滚动效果不起作用
问题描述
在我的角度应用程序中,使用引导程序我在另一个模态中创建了一个模态。首先,您将看到用于加载第一个模式的按钮。现在您可以看到滚动效果。但是如果加载第二个模态并关闭它,那么第一个模态的滚动效果就不再起作用了。我该如何解决这个问题? 请参阅此处的示例
这是代码示例,您还可以查看上面的链接:
<a data-toggle="modal" href="#myModal" class="btn btn-primary">Click Me</a>
<div class="modal" id="myModal">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Modal title</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div><div class="container"></div>
<div class="modal-body">
Scrollin effect for this modal is working at the beginning.
But if load the 2nd modal and close it, then this scrolling effect is not working anymore.
--------------------------------------------------------
Scrollin effect for this modal is working at the beginning.
But if load the 2nd modal and close it, then this scrolling effect is not working anymore.
--------------------------------------------------------
Scrollin effect for this modal is working at the beginning.
But if load the 2nd modal and close it, then this scrolling effect is not working anymore.
--------------------------------------------------------
Scrollin effect for this modal is working at the beginning.
But if load the 2nd modal and close it, then this scrolling effect is not working anymore.
--------------------------------------------------------
Scrollin effect for this modal is working at the beginning.
But if load the 2nd modal and close it, then this scrolling effect is not working anymore.
--------------------------------------------------------
Scrollin effect for this modal is working at the beginning.
But if load the 2nd modal and close it, then this scrolling effect is not working anymore.
--------------------------------------------------------
Scrollin effect for this modal is working at the beginning.
But if load the 2nd modal and close it, then this scrolling effect is not working anymore.
--------------------------------------------------------
Scrollin effect for this modal is working at the beginning.
But if load the 2nd modal and close it, then this scrolling effect is not working anymore.
--------------------------------------------------------
<a data-toggle="modal" href="#myModal2" class="btn btn-primary">Launch modal</a>
</div>
<div class="modal-footer">
<a href="#" data-dismiss="modal" class="btn">Close</a>
</div>
</div>
</div>
</div>
<div class="modal" id="myModal2" data-backdrop="static">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">2nd Modal title</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div><div class="container"></div>
<div class="modal-body">
Content for the dialog / modal goes here.
Content for the dialog / modal goes here.
Content for the dialog / modal goes here.
Content for the dialog / modal goes here.
Content for the dialog / modal goes here.
</div>
<div class="modal-footer">
<a href="#" data-dismiss="modal" class="btn">Close</a>
</div>
</div>
</div>
</div>
解决方案
基本上,有两种选择可以解决这个问题:
- 添加
.modal-dialog-scrollable
到您的模式中,仅使其内容可滚动,而不是整个容器。看看这个小提琴。
<div class="modal" id="myModal">
<div class="modal-dialog modal-lg modal-dialog-scrollable">
<div class="modal-content">
...
</div>
</div>
$(document).on('hidden.bs.modal', '.modal', function () {
$('.modal:visible').length && $(document.body).addClass('modal-open');
});
祝你好运!
推荐阅读
- go - 将动态参数传递给函数
- azure-active-directory - 使用 loginwithazureactivedirectory 和 expressmode 的 Azure 活动目录
- json - 使用 JsonConvert.Deserialize 时变量显示“无”
- python - “a:1”不应该是python中的语法错误吗?
- acumatica - 使用 DLL 发布 Acumatica 导致 System.BadImageFormatException
- http - ETag 标头是否会使 Cache-Control 标头过时?那么如何确保 Cache-Control 无害呢?
- java - Hibernate:实体管理器工厂的问题
- python-3.x - “如何在 PYTHON 中接收声音以及如何根据其频率对其进行区分”
- android - 快照与当前 VM 配置 Flutter 不兼容
- python - Python中的自定义异常 - 变量的测试值