부트스트랩 JS 모달


JS 모달(modal.js)

Modal 플러그인은 현재 페이지 상단에 표시되는 대화 상자/팝업 창입니다.

모달 에 대한 튜토리얼은 부트스트랩 모달 튜토리얼 을 읽어보세요 .


모달 플러그인 클래스

Class Description
.modal Creates a modal
.modal-content Styles the modal properly with border, background-color, etc. Use this class to add the modal's header, body, and footer.
.modal-header Defines the style for the header of the modal
.modal-body Defines the style for the body of the modal
.modal-footer Defines the style for the footer in the modal. Note: This area is right-aligned by default. To change this, overwrite CSS with text-align:left|center
.modal-sm Specifies a small modal
.modal-lg Specifies a large modal
.fade Adds an animation/transition effect which fades the modal in and out

데이터-* 속성을 통해 모달 트리거

모든 요소에 data-toggle="modal"and 를 추가 합니다.data-target="#modalID"

참고: 요소의 경우 <a>생략 data-target하고 href="#modalID"대신 사용하십시오.

예시

<!-- Buttons -->
<button type="button" data-toggle="modal" data-target="#myModal">Open Modal</button>

<!-- Links -->
<a data-toggle="modal" href="#myModal">Open Modal</a>

<!-- Other elements -->
<p data-toggle="modal" data-target="#myModal">Open Modal</p>


JavaScript를 통해 트리거

다음을 사용하여 수동으로 활성화:

예시

$("#myModal").modal()

모달 옵션

옵션은 데이터 속성 또는 JavaScript를 통해 전달할 수 있습니다. 데이터 속성의 경우 data-backdrop=""에서와 같이 옵션 이름을 data-에 추가합니다.

Name Type Default Description Try it
backdrop boolean or the string "static" true Specifies whether the modal should have a dark overlay:

  • true - dark overlay
  • false - no overlay (transparent)

If you specify the value "static", it is not possible to close the modal when clicking outside of it

keyboard boolean true Specifies whether the modal can be closed with the escape key (Esc):

  • true - the modal can be closed with Esc
  • false - the modal cannot be closed with Esc
show boolean true Specifies whether to show the modal when initialized

모달 방법

다음 표에는 사용 가능한 모든 모달 방법이 나열되어 있습니다.

Method Description Try it
.modal(options) Activates the content as a modal. See options above for valid values
.modal("toggle") Toggles the modal
.modal("show") Opens the modal
.modal("hide") Hides the modal

모달 이벤트

다음 표에는 사용 가능한 모든 모달 이벤트가 나열되어 있습니다.

Event Description Try it
show.bs.modal Occurs when the modal is about to be shown
shown.bs.modal Occurs when the modal is fully shown (after CSS transitions have completed)
hide.bs.modal Occurs when the modal is about to be hidden
hidden.bs.modal Occurs when the modal is fully hidden (after CSS transitions have completed)

더 많은 예

로그인 모달

다음 예는 로그인을 위한 모달을 생성합니다:

예시

<div class="container">
  <h2>Modal Login Example</h2>
  <!-- Trigger the modal with a button -->
  <button type="button" class="btn btn-default btn-lg" id="myBtn">Login</button>

  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 style="color:red;"><span class="glyphicon glyphicon-lock"></span> Login</h4>
        </div>
        <div class="modal-body">
          <form role="form">
            <div class="form-group">
              <label for="usrname"><span class="glyphicon glyphicon-user"></span> Username</label>
              <input type="text" class="form-control" id="usrname" placeholder="Enter email">
            </div>
            <div class="form-group">
              <label for="psw"><span class="glyphicon glyphicon-eye-open"></span> Password</label>
              <input type="text" class="form-control" id="psw" placeholder="Enter password">
            </div>
            <div class="checkbox">
              <label><input type="checkbox" value="" checked>Remember me</label>
            </div>
            <button type="submit" class="btn btn-default btn-success btn-block"><span class="glyphicon glyphicon-off"></span> Login</button>
          </form>
        </div>
        <div class="modal-footer">
          <button type="submit" class="btn btn-default btn-default pull-left" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> Cancel</button>
          <p>Not a member? <a href="#">Sign Up</a></p>
          <p>Forgot <a href="#">Password?</a></p>
        </div>
      </div>
    </div>
  </div>
</div>