jquery - 在移动 boostrap 4 上禁用模式
问题描述
我们可以在移动设备上禁用 Modals 吗?
我查看了其他线程,但自从开始编写脚本以来,我也不太明白,如果有必要的话,我不知道如何使用 jquery。
这是我的脚本。
<div class="col-sm" >
<input type="image" src="horse.png" class="img-thumbnail" data-toggle="modal" data-target=".horseModal-modal-lg">
<div class="modal fade horseModal-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<img class="img-responsive" src="horse.png" id="imageSize">
</div>
</div>
</div>
</div>
解决方案
最安全的方法是根本不在手机上显示模态切换:
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css">
<button type="button" class="btn btn-primary d-none d-sm-inline-block"
data-toggle="modal" data-target="#yourModal">
Launch modal
</button>
注意d-none d-sm-inline-block
按钮上的类。根据display
您在呈现模式切换时想要的值,您可能希望将其更改为d-sm-flex
d-sm-block
或d-sm-inline
。
如果您想从768px
向上(而不是545px
向上)开始显示模式,请使用d-md-*
类。或者d-lg-*
从上面开始展示它992px
。
更糟糕的选择是将整个模态包装在一个类似的元素中
<div class="d-none d-sm-block">
your modal markup here
</div>
...但是触发模态的afaik无论如何都会启用模态背景。
更糟糕的选择是使用一个库来检查当前设备是否是移动的,并阻止以编程方式打开模式。
推荐阅读
- ios - 在测试/展示 iOS 应用程序时动态移动 userLocation 的方法?
- excel - Excel 计算问题
- javascript - Winston javascript 记录器正在创建两个单独的日志文件。如何将所有条目记录到一个文件中?
- java - 二进制文件的Java列表迭代器 - 问题
- javascript - 如何将元组从 javascript 传递到 ASP.NET MVC 控制器操作
- python - 网页不会在三分钟内生成输出并死掉。连接在哪里消亡?
- javascript - Vega 中带有调整大小手柄的时间范围选择器
- angular - 在 Angular 8 中使用 FullerCalendar,如何添加点击日历上的日期的事件?
- r - 使用 dplyr 在 R 中排除 28 个不同月份的子数据框
- python - 如何在截屏之前最小化 tkinter 应用程序然后最大化