ModalBox is a powerfull jQuery plugin which can be used to highlight a photo, video, map, AJAX content or inline HTML content. ModalBox can also be used to show Alert, Confirm or Prompt boxes. Plugin works every where including PC, iPad, iPhone and Android.
Inline content works great with ModalBox, like this subscribe form.
Use Modalbox to show alert, confirm and prompts on you page.
This script goes into head section
<!-- Include jQuery Library --> <script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js" type="text/javascript"></script> <!-- Include Modal Box CSS file --> <link href="modal.css" rel="Stylesheet" /> <link href="modal-darktheme.css" rel="Stylesheet" /> <!-- Include Modal Box Script File --> <script src="modal.js" type="text/javascript"></script> <!-- Script to initialize Modal Box --> <script type="text/javascript"> $(document).ready(function () { $(".photo").modalbox({ Type: 'image' }); $(".gallery").modalbox({ Type: 'image' }); $("#youtube").modalbox({ Type: 'iframe', Width: 560, Height: 315, Modal: true }); $(".iframe").modalbox({ Type: 'iframe', Width: 600, Height: 400 }); $("#inline").modalbox({ Type: 'inline', Width: 400, Height: 300 }); $("#ajax").modalbox({ Type: 'ajax', Width: 600, Height: 400 }); }); </script>
HTML Example
<!-- Body Section HTML --> <!-- Individual Photo Modal Box --> <a href="pic6.jpg" class="photo" title="This is sample title for this photo."> <img class="thumb img-polaroid" src="pic6.jpg" alt="" /> </a> <a href="pic7.jpg" class="photo" title="This is sample title for this photo."> <img class="thumb img-polaroid" src="pic7.jpg" alt="" /> </a> <!-- Photo Gallery Modal Box --> <a href="pic1.jpg" class="gallery" rel="group1" title="Sample title for gallery photo 1."> <img class="thumb img-polaroid" src="pic1.jpg" alt="" /> </a><a href="pic2.jpg" class="gallery" title="Sample title for gallery photo 2." rel="group1"> <img class="thumb img-polaroid" src="pic2.jpg" alt="" /> </a><a href="pic3.jpg" class="gallery" title="Sample title for gallery photo 3." rel="group1"> <img class="thumb img-polaroid" src="pic3.jpg" alt="" /> </a><a href="pic4.jpg" class="gallery" title="Sample title for gallery photo 4." rel="group1"> <img class="thumb img-polaroid" src="pic4.jpg" alt="" /> </a><a href="pic5.jpg" class="gallery" title="Sample title for gallery photo 5." rel="group1"> <img class="thumb img-polaroid" src="pic5.jpg" alt="" /> </a> <ul> <!-- Using a youtube embed url to show in modal box --> <li><a href="//www.youtube-nocookie.com/embed/F983K9pFk9s?rel=0" id="youtube">Youtube</a></li> <!-- Google Map Url --> <li>Google maps <ul> <li><a class="iframe" href="//maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=Taj+Mahal,+Agra,+Uttar+Pradesh,+India&aq=0&oq=Taj+&sll=24.831845,79.919855&sspn=0.092695,0.154324&t=h&g=Khajuraho,+Madhya+Pradesh,+India&ie=UTF8&hq=Taj+Mahal,+Agra,+Uttar+Pradesh,+India&ll=27.172988,78.042139&spn=0.006295,0.006295&output=embed"> Search results</a></li> <li><a class="iframe" href="//maps.google.com/?t=h&ie=UTF8&ll=48.85796,2.295231&spn=0.0042,0.009645&z=17&output=embed"> Direct link</a></li> <li><a class="iframe" href="//maps.google.com/?t=m&layer=c&cbll=48.859507,2.292568&panoid=YJ0lq28OOy3VT2IqIuVY0g&cbp=12,151.58,,0,-15.56&ie=UTF8&ll=48.859358,2.292787&spn=0.00105,0.002411&z=19&source=embed&output=svembed"> Street view</a></li> </ul> </li> <!-- inline example --> <li><a href="#modal1" id="inline">Inline</a></li> <!-- ajax example --> <li><a href="js-tools/modal/sample.txt" id="ajax">Ajax</a></li> </ul> <div id="moda1" style="display: none;"> This is inline content that will be show inside the Modal Box. Modal box makes it easy to implement this behavior. You can show any html inside modal box including images, paragraphs etc. <img class="thumb" src="pic6.jpg" alt="" /> I have written this text just to take some more space. </div>
Alert, Confirm and Prompt
<button onclick="$.fn.modalbox('alert', {Message : 'Hi, <br/> I am ModalBox, I can work everywhere and make your webpage beautiful'})" class="btn">Alert</button> <button onclick="$.fn.modalbox('confirm', {Message : '<h4>You are interested in downloading this plugin. Please Confirm?</h4>', Action: function(val) { if(val){ $.fn.modalbox('alert', {Message : 'Thanks please check the Download option at the bottom menu.'}); } else { $.fn.modalbox('alert', {Message : 'Why So????'}); }} })" class="btn">Confirm</button> <button onclick="$.fn.modalbox('prompt', {Message : 'What is you Name?', Action: function(val){ if(val != '') { $.fn.modalbox('alert', {Message : val }); } }})" class="btn">Prompt</button>
for Photos, Youtube Videos, Maps or Inline HTML
Option | Default | Description |
---|---|---|
Type | 'image' |
'image' | 'iframe' | 'inline' | 'ajax' |
Width | 600 |
Set width of modal content. Note: if type is set to 'image' this option might be overridden with images actual width. Width : 600 or Width : "80%"
|
Height | 350 |
Set height of modal content. Option is used only for type iframe, inline and ajax. Height : 500 or Height : "80%"
|
CloseHandle | null |
Expects a jquery object like $("#closebutton"). Use this option to set custom close
button. Option should be used when type is set to 'inline'. |
OnInit | null |
Expects a function. Function will be called at the time of initialization of modal
box for any element(s).
OnInit : function() { /* Do Work Here */ } |
OnShow | null |
Expects a function. Function will be called when modal box is shown. OnShow : function(index) { /* index: current item index if in gallery mode else it will be 0 */ /* Do Work Here */ } |
OnClose | null |
Expects a function. Function will be called when modal box is closed.
OnClose : function() { /* Do Work Here */ } |
for Alert
Option | Default | Description |
---|---|---|
Message | Empty | Any text |
OkText |
'<u>O</u>K'
|
Text |
OnInit | null |
Expects a function. Function will be called at the time of initialization of modal box. OnInit : function() { /* Do Work Here */ } |
OnShow | null |
Expects a function. Function will be called when modal box is shown. OnShow : function() { /* Do Work Here */ } |
OnClose | null |
Expects a function. Function will be called when modal box is closed. OnClose : function() { /* Do Work Here */ } |
for Confirm
Option | Default | Description |
---|---|---|
Message | Empty | Any text |
YesText |
'<u>Y</u>es'
|
Text |
NoText |
'<u>N</u>o'
|
Text |
CancelText |
'<u>C</u>ancel'
|
Text |
Action |
function (val) { }
|
function |
OnInit | null |
Expects a function. Function will be called at the time of initialization of modal box. OnInit : function() { /* Do Work Here */ } |
OnShow | null |
Expects a function. Function will be called when modal box is shown. OnShow : function() { /* Do Work Here */ } |
OnClose | null |
Expects a function. Function will be called when modal box is closed. OnClose : function() { /* Do Work Here */ } |
for Prompt
Option | Default | Description |
---|---|---|
Message | Empty | Any text |
OkText |
'<u>O</u>k'
|
Text |
Action |
function (val) { }
|
function |
OnInit | null |
Expects a function. Function will be called at the time of initialization of modal box. OnInit : function() { /* Do Work Here */ } |
OnShow | null |
Expects a function. Function will be called when modal box is shown. OnShow : function() { /* Do Work Here */ } |
OnClose | null |
Expects a function. Function will be called when modal box is closed. OnClose : function() { /* Do Work Here */ } |
You can right click and click "Save Target As". Please bookmark this page for future download of Question plugin. Visit Question Plugin page for examples and how to use.
For any kind of support for this script please write an email to me rajk...@rudrasofttech.com.