A simple library tinked to easy Materialize JavaScript Modals
<div id="modal1" class="modal"> <div class="modal-content"> <h4>Alert</h4> <p>Hello</p> </div> <div class="modal-footer"> <a href="#!" class="btn modal-close">Close</a> </div> </div>
MaterialDialog.alert("Hello");
Download the source here
Include materialize css and js in head.
<head> <link href="src/materialize/css/materialize.css" rel="stylesheet" type="text/css"> <script src="src/materialize/js/materialize.js" type="text/javascript"></script> <script src="src/material-dialog.js" type="text/javascript"></script> </head>
Material Dialog need materialize css and js
Usage Example
MaterialDialog.alert(
'Message', // Alert Body (Acepts html tags)
{
title:'Alert Modal', // Modal title
buttons:{ // Receive buttons (Alert only use close buttons)
close:{
text:'close', //Text of close button
className:'red', // Class of the close button
callback:function(){ // Function for modal click
alert("hello")
}
}
}
}
);
Options
| Method | Description |
|---|---|
| title | Modal's Title |
buttons
|
|
Usage Example
MaterialDialog.dialog(
"Text here",
{
title:"Dialog Title",
modalType:"modal-fixed-footer", // Can be empty, modal-fixed-footer or bottom-sheet
buttons:{
// Use by default close and confirm buttons
close:{
className:"red",
text:"closed",
callback:function(){
alert("closed!");
}
},
confirm:{
className:"blue",
text:"confirmed",
modalClose:false,
callback:function(){
console.log("confirmed");
}
}
}
}
);
Options
| Method | Description |
|---|---|
| title | Modal's Title |
buttons
|
|
In options part, you can pass any materialize modal property's, for more info check here
MaterialDialog.alert(
'Message', // Alert Body (Acepts html tags)
{
title:'Alert Modal', // Modal title
dismissible: false, // Modal can be dismissed by clicking outside of the modal
opacity: .5, // Opacity of modal background
inDuration: 300, // Transition in duration
outDuration: 200, // Transition out duration
startingTop: '4%', // Starting top style attribute
endingTop: '10%', // Ending top style attribute
onOpenStart: function(modal) { // Callback for Modal open
console.log(modal);
},
onCloseEnd: function() { alert('Closed'); } // Callback for Modal close
}
);