利用Bootstrap 模态框(Modal)实现loading框效果

利用Bootstrap 模态框(Modal)实现loading框效果

<div class="modal fade" id="loadingModal" backdrop="static" keyboard="false">
      
    <div style="width: 200px;height:100px; z-index: 20000; position: absolute; text-align: center; left: 50%; top: 50%;margin-left:-100px;margin-top:-10px">
            
        <div class="progress progress-striped active"
             style="margin-bottom: 0;height:50px; text-align:center;line-height: 50px;font-size:large;">
              数据加载中,请稍候......    
        </div>
          
    </div>
</div>

<script>
//展示loading框
showLoading = function ()
{
     $('#loadingModal').modal({backdrop: 'static', keyboard: false});
}
//隐藏掉loading框
hideLoading = function ()
{
     $('#loadingModal').modal('hide');
}
</script>

参考:https://www.runoob.com/bootstrap/bootstrap-modal-plugin.html

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Bootstrap 是一个流行的前端架,它提供了许多实用的组件,其中包括模态框。下面是使用 Bootstrap 实现模态框的基本步骤: 1. 引入 Bootstrap 样式文件和 JavaScript 文件,可以通过 CDN 或本地文件引入。 ```html <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css"> <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.0/js/bootstrap.min.js"></script> ``` 2. 在 HTML 文件中添加一个触发模态框的按钮,使用 `data-toggle` 和 `data-target` 属性指定模态框的 ID。 ```html <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal"> 打开模态框 </button> ``` 3. 添加一个模态框的 HTML 结构,包括模态框的头部、主体和尾部,使用 `id` 属性指定模态框的 ID。 ```html <div class="modal fade" id="myModal"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">模态框标题</h5> <button type="button" class="close" data-dismiss="modal">×</button> </div> <div class="modal-body"> <p>模态框内容...</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button> <button type="button" class="btn btn-primary">保存</button> </div> </div> </div> </div> ``` 4. 完成上述步骤后,点击按钮即可触发模态框的显示。如果需要通过 JavaScript 控制模态框的显示和隐藏,可以使用 Bootstrap 提供的 JavaScript API,如下所示: ```javascript // 显示模态框 $('#myModal').modal('show'); // 隐藏模态框 $('#myModal').modal('hide'); ``` 以上就是使用 Bootstrap 实现模态框的基本步骤。需要注意的是,Bootstrap模态框有很多可选参数和事件,可以根据实际情况进行配置和使用。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值