Dinamic and simple modal generator
One modal to rule them all
Create a modal in one line, then update the content whenever you need.
new iModal({
title: 'Hello',
body: '<p>This is a simple modal.</p>'
});
iModal.body(...) to change the content later.iModal.hide() or let it disappear automatically.Most useful options: title, body, size, bg, draggable, backdrop, dialogCentered, and autoHide.
These are enough to create simple, polished modals without needing to remember the full API.
| Method | Description |
|---|---|
| iModal.setSettings(object) | Set global settings |
| iModal.isActive() | return boolean |
| iModal.hide() | Graceful hidden iModal |
| iModal.remove() | remove iModal |
| iModal.version | return iModal version |
A few extra combinations to explore once the basics feel familiar.
new iModal();
new iModal({size:'lg'});
new iModal({fullscreen:true});
// More options: sm, md, lg, xl, xxl, true, false
new iModal({title:'Hello world'});
iModal.body('Custom html');
new iModal({bg:'success'});
new iModal({autoHide:true, autoHideTime:1800});
new iModal({backdrop:false});
new iModal({draggable:true});
new iModal({dialogCentered:true});
Useful methods: iModal.hide(), iModal.remove(), and iModal.isActive().
Useful options: title, body, size, bg, backdrop, and autoHide.
Try changing the modal title, body, size, color, or backdrop to see how the library behaves.
For most use cases, the basic API is enough to build a polished experience quickly.
new iModal({title:'Success',bg:'success',autoHide:true});
new iModal({title:'Success',bg:'success',autoHide:true,autoHideTime:3000});
new iModal({ onShow: function(){ alert('Show'); } });
new iModal({ onShowed: function(){ alert('Showed'); } });
new iModal({ onHide: function(){ alert('Hide'); } });
new iModal({ onHidden: function(){ alert('Hidden'); } });
new iModal({ backdrop: 'static', onHidePrevented: function(){ alert('Hide Prevented'); } });
new iModal({id:'my_modal'});
new iModal({
id:'my_modal',
size:'sm',
title:'Custom modal',
closeText:'Cerrar',
body:'Cargando...',
headerClass:'success',
footerClass:'success',
backdrop:false,
keyboard:false,
dialogCentered:true,
fade:false,
autoHide:true,
autoHideTime:3000,
});
function isActive(){
alert(iModal.isActive());
}
iModal({
body: `<button class='btn btn-primary' onclick='isActive();'>isActive?</button>`
});
function hide(){
iModal.hide();
}
iModal({
body: `<button class='btn btn-primary' onclick='hide();'>Hide modal</button>`
});
function remove(){
iModal('remove');
}
iModal({
body: `<button class='btn btn-primary' onclick='remove();'>Remove modal</button>`
});
alert(iModal.version);
iModal.setSettings({
id: 'my_modal',
size: 'lg',
title: 'My project',
backdrop: false,
});
See all the documentation in GitHub.