1.打开官网

Modal · Bootstrap v5.1 | Bootstrap官方文档中国镜像

2.选择组件

说明:Components下的modal 

 3.选择喜欢的样式

说明:本次选择的是Live demo,为了展示更多的可操作性,本次将不用上面的Button trigger modal,采用的是自己创建并触发。

4. 粘贴到html文件

说明:我修改了id为了后面初始化modal(目的是增加可操作性)

    <!-- 预览模态框 -->
    <div
      class="modal fade"
      id="preview"
      tabindex="-1"
      aria-labelledby="exampleModalLabel"
      aria-hidden="true"
    >
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
            <button
              type="button"
              class="btn-close"
              data-bs-dismiss="modal"
              aria-label="Close"
            ></button>
          </div>
          <div class="modal-body">...</div>
          <div class="modal-footer">
            <button
              type="button"
              class="btn btn-secondary"
              data-bs-dismiss="modal"
            >
              Close
            </button>
            <button type="button" class="btn btn-primary">Save changes</button>
          </div>
        </div>
      </div>
    </div>

5.点击Via JavaScript 

 

6. 初始化

说明:上面我已经修改过了id,因此用preview获取。

// 初始预览模态框
var preview = new bootstrap.Modal(document.getElementById('preview'))

7. 点击切换转态
说明:来回切换show,hide。

8.演练

说明:为预览绑定了点击事件

    preview.toggle()

 

 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐