modals have three optional sizes .n-modal-sm, .n-modal-lg, and .n-modal-xl which can be apply in .n-modal-dialog class.
<button data-modal="#live-modal-sm" class="n-btn">Small Modal</button><button data-modal="#live-modal-lg" class="n-btn">Large Modal</button><button data-modal="#live-modal-xl" class="n-btn">Extra Large Modal</button><div id="live-modal-sm" class="n-modal" tabindex="-1" role="dialog"><div class="n-modal-dialog n-modal-sm"><div class="n-modal-content"><div class="n-modal-header"><h5 class="n-modal-title">Modal Title</h5><button class="n-btn n-btn-xs" data-dismiss="modal">&times;</button></div><div class="n-modal-body"><p>Small modal.</p></div><div class="n-modal-footer"><button class="n-btn" data-dismiss="modal">Close</button></div></div></div></div><div id="live-modal-lg" class="n-modal" tabindex="-1" role="dialog"><div class="n-modal-dialog n-modal-lg"><div class="n-modal-content"><div class="n-modal-header"><h5 class="n-modal-title">Modal Title</h5><button class="n-btn n-btn-xs" data-dismiss="modal">&times;</button></div><div class="n-modal-body"><p>Large modal.</p></div><div class="n-modal-footer"><button class="n-btn" data-dismiss="modal">Close</button></div></div></div></div><div id="live-modal-xl" class="n-modal" tabindex="-1" role="dialog"><div class="n-modal-dialog n-modal-xl"><div class="n-modal-content"><div class="n-modal-header"><h5 class="n-modal-title">Modal Title</h5><button class="n-btn n-btn-xs" data-dismiss="modal">&times;</button></div><div class="n-modal-body"><p>Extra Large modal.</p></div><div class="n-modal-footer"><button class="n-btn" data-dismiss="modal">Close</button></div></div></div></div>
using N.modal.getInstance(modalElement) it can initialize the .n-modal when it is not initialize yet and get the instance at the same time. if the .n-modal is already initialize, it will only get the instance.
document.addEventListener("DOMContentLoaded", (event) => {// apply the modal script to all .n-modal elementconst elements = document.querySelectorAll('.n-modal')elements.forEach((el) => {const instance = N.modal.getInstance(el)});})
Method Method | Return Return | Description Description |
---|---|---|
Instance.show | void | to show the modal programmatically. |
Instance.close | void | to close the modal programmatically. |
Instance.destroy | void | it is use to destroy and kill the modal instance. |
All modal events are fired at the .n-modal element.
Event Event | Description Description |
---|---|
show.n.modal | This event fires immediately when the show instance method is called. |
shown.n.modal | This event fires when the modal is completely shown (CSS transition is complete). |
hide.n.modal | This event fires immediately when the close instance method is called. |
hidden.n.modal | This event fires when the modal is completely hidden (CSS transition is complete). |
const modal = document.querySelector('#my-modal')modal.addEventListener('show.n.modal'. (event) => {// do something here...})