Bootstrap JS Modal

Modal CSS Classes

For a tutorial about Modals, read our Bootstrap Modal Tutorial.

ClassDescriptionExample
.modalCreates a modalTry it
.modal-contentStyles the modal properly with border, background-color, etc. Use this class to add the modal's header, body, and footerTry it
.modal-dialog-centeredCenters the modal vertically and horizontally within the pageTry it
.modal-dialog-scrollableAdds a scrollbar inside the modalTry it
.modal-headerDefines the style for the header of the modalTry it
.modal-bodyDefines the style for the body of the modalTry it
.modal-footerDefines the style for the footer in the modal. Note: This area is right-aligned by default. To change this, add the justify-content-start or justify-content-center together with the .modal-footer classTry it
.modal-smSpecifies a small modalTry it
.modal-lgSpecifies a large modalTry it
.fadeAdds an animation/transition effect which fades the modal in and outTry it

Trigger the Modal Via data-* Attributes

Add data-toggle="modal" and data-target="#modalID" to any element.
Note: For <a> elements, omit data-target, and use href="#modalID" instead:

Example

<!-- 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>
Try it Yourself »

Trigger Via JavaScript

Enable manually with:

Example

$("#myModal").modal()
Try it Yourself »

Modal Options

Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-, as in data-backdrop="".
NameTypeDefaultDescriptionTry it
backdropboolean or the string "static"trueSpecifies 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
Using JSUsing data
keyboardbooleantrueSpecifies 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
Using JSUsing data
showbooleantrueSpecifies whether to show the modal when initializedUsing JSUsing data

Modal Methods

The following table lists all available modal methods.
MethodDescriptionTry it
.modal(options)Activates the content as a modal. See options above for valid valuesTry it
.modal("toggle")Toggles the modalTry it
.modal("show")Opens the modalTry it
.modal("hide")Hides the modalTry it

Modal Events

The following table lists all available modal events.
EventDescriptionTry it
show.bs.modalOccurs when the modal is about to be shownTry it
shown.bs.modalOccurs when the modal is fully shown (after CSS transitions have completed)Try it
hide.bs.modalOccurs when the modal is about to be hiddenTry it
hidden.bs.modalOccurs when the modal is fully hidden (after CSS transitions have completed)Try it



Credit: www.w3schools.com
Bootstrap JS Modal Bootstrap JS Modal Reviewed by webmission on 11:10 Rating: 5

No comments:

Powered by Blogger.