Home > Web Front-end > JS Tutorial > Bootstrap modal box (Modal) plug-in that you must learn every day_javascript skills

Bootstrap modal box (Modal) plug-in that you must learn every day_javascript skills

WBOY
Release: 2016-05-16 15:03:42
Original
1682 people have browsed it

In this lesson we will mainly learn about the modal box plug-in in Bootstrap, which is a very common pop-up function plug-in for interactive websites.

1. Basic usage
Using a modal box pop-up component requires three layers of div container elements, namely modal (modal declaration layer),
dialog (window declaration layer), content (content layer). Within the content layer, there are three layers, namely header, body, and footer.
//Basic example

<!-- 模态声明,show 表示显示 -->
<div class="modal show" tabindex="-1">
  <!-- 窗口声明 -->
  <div class="modal-dialog">
    <!-- 内容声明 -->
    <div class="modal-content">
      <!-- 头部 -->
      <div class="modal-header">
        <button type="button" class="close"
        data-dismiss="modal">
          <span>&times;</span>
        </button>
        <h4 class="modal-title">会员登录</h4>
      </div>
      <!-- 主体 -->
      <div class="modal-body">
        <p>
          暂时无法登录会员
        </p>
      </div>
      <!-- 注脚 -->
      <div class="modal-footer">
        <button type="button" class="btn btn-default">
          注册
        </button>
        <button type="button" class="btn btn-primary">
          登录
        </button>
      </div>
    </div>
  </div>
</div>

Copy after login

If you want the modal box to hide automatically and then pop up the window by clicking the button, you need to do the following.

//模态框去掉 show,增加一个 id

<div class="modal" id="myModal">
//点击触发模态框显示

<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  点击弹窗
</button>
//弹窗的大小有三种,默认情况下是正常,还有 lg(大)和 sm(小)

<div class="modal-dialog modal-lg">
<div class="modal-dialog sm-lg">
//可设置淡入淡出效果

<div class="modal fade" id="myModal">
//在主体部分使用栅格系统中的流体


<!-- 主体 -->
<div class="modal-body">
  <div class="container-fluid">
    <div class="row">
      <div class="col-md-4">
        1
      </div>
      <div class="col-md-4">
        1
      </div>
      <div class="col-md-4">
        1
      </div>
    </div>
  </div>
</div>

Copy after login

2. Instructions for use
After the basic usage introduction, let’s take a look at the various important uses of the plug-in. All plug-ins are based on JavaScript/jQuery. Then, there are four elements: usage, parameters, methods and events.
1. Usage
The first type: You can pass the data attribute

//data-toggle

data-toggle="modal" data-target="#myModal"

Copy after login

data-toggle indicates trigger type
data-target represents the triggered node

If instead of using

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template