jQuery Modal Window Effects with transitions CSS3.
Please note: these animations only works as intended in browsers that support the respective CSS properties.
Internet Explorer 8 and 9 works, but without animations.
This plugin is created with native JavaScript but works perfectly with jQuery.
If you do not want to use jQuery click here.
1) Rename the file jquery.custombox.js by custombox.js (obviously).
2) In the file jquery.custombox.js replace this code:
// A really lightweight plugin wrapper around the constructor, // preventing against multiple instantiations with jQuery. $.fn[ cb ] = function ( options ) { var args = arguments, isElement = typeof HTMLElement === 'object' ? options instanceof HTMLElement : options && typeof options === 'object' && options !== null && options.nodeType === 1 && typeof options.nodeName === 'string'; if ( options === undefined || typeof options === 'object' ) { if ( isElement ) { if ( navigator.appName === 'Microsoft Internet Explorer' ) { //Write a new regEx to find the version number var re = new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})"); //If the regEx through the userAgent is not null if (re.exec(navigator.userAgent) != null) { //Set the IE version var version = parseInt(RegExp.$1); } } if ( typeof version === 'undefined' || version >= 10 ) { // Check time to avoid double click. if ( options.dataset[cb] !== undefined && parseInt(options.dataset[cb]) + 1 > Math.round( new Date().getTime() / 1000 )) { return; } // Set time to avoid double click. options.setAttribute('data-' + cb, Math.round( new Date().getTime() / 1000 ) ); } $(options).each( function () { $.data( this, cb, new Plugin( this, args[1] ) ); }); } else { new Plugin( null, args[0] ); } } else if ( typeof options === 'string' && options === 'close' ) { $.data( this, cb, new Plugin( args[0], args[1] ) ); } };
By this:
// A really lightweight plugin wrapper around the constructor, // preventing against multiple instantiations. window[ cb ] = function ( options ) { var isElement = typeof HTMLElement === 'object' ? options instanceof HTMLElement : options && typeof options === 'object' && options !== null && options.nodeType === 1 && typeof options.nodeName === 'string'; if ( options === undefined || typeof options === 'object' ) { if ( isElement ) { if ( navigator.appName === 'Microsoft Internet Explorer' ) { //Write a new regEx to find the version number var re = new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})"); //If the regEx through the userAgent is not null if (re.exec(navigator.userAgent) != null) { //Set the IE version var version = parseInt(RegExp.$1); } } if ( typeof version === 'undefined' || version >= 10 ) { // Check time to avoid double click. if ( options.dataset[cb] !== undefined && parseInt(options.dataset[cb]) + 1 > Math.round( new Date().getTime() / 1000 )) { return; } // Set time to avoid double click. options.setAttribute('data-' + cb, Math.round( new Date().getTime() / 1000 ) ); } new Plugin( arguments[0], arguments[1] ); } else { new Plugin( null, arguments[0] ); } } else if ( typeof options === 'string' && options === 'close' ) { new Plugin( arguments[0], arguments[1] ); } };
Call the plugin when the body is on load:
<script> window.onload = function () { document.getElementById('example').addEventListener('click', function () { custombox( this, { effect: 'fadein' }); }, false ); }; </script>
1) Include jQuery (Compatible with v1.7+):
In just about every case, it's best to place all your script references at the end of the page, just before: </body>
.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
2) Include jquery.custombox.js code:
In just about every case, it's best to place all your script references at the end of the page, just before: </body>
.
<script src="src/jquery.custombox.js"></script>
3) Include jquery.custombox.css code:
Insert it in the section of your HTML document, after: <html>
.
<link rel="stylesheet" href="src/jquery.custombox.css">
4) Call the plugin when the body is on load:
<script> $(function () { $('#element').on('click', function () { $.fn.custombox( this ); return false; }); }); </script>
Property | Default | Description |
---|---|---|
url | null | Set the URL, ID or Class. |
cache | false | If set to false, it will force requested pages not to be cached by the browser only when send by AJAX. |
escKey | true | Allow the user to close the modal by pressing 'ESC'. |
eClose | null | Element ID or Class to close the modal. |
zIndex | 9999 | Overlay z-index: Number or auto. |
overlay | true | Show the overlay. |
overlayColor | #000 | Overlay color. |
overlayOpacity | 0.8 | The overlay opacity level. Range: 0 to 1. |
overlayClose | true | Allow the user to close the modal by clicking the overlay. |
overlaySpeed | 200 | Sets the speed of the overlay, in milliseconds. |
customClass | null | Custom class to modal. |
width | null | Set a fixed total width. |
height | null | Set a fixed total height. |
effect | fadein | fadein | slide | newspaper | fall | sidefall | blur | flip | sign | superscaled | slit | rotate | letmein | makeway | slip. |
position | null | Only with effects: slide, flip and rotate. (top, right, bottom and left) | (vertical or horizontal). |
speed | 600 | Sets the speed of the transitions, in milliseconds. |
open | null | Callback that fires right before begins to open. |
complete | null | Callback that fires right after loaded content is displayed. |
close | null | Callback that fires once is closed. |
error | Error 404! | Text to be displayed when an error. |
$.fn.custombox('close') | Allow the user to close the modal. |
- Example
$('#example1').on('click', function () { $.fn.custombox( this, { overlay: false, effect: 'fadein' }); return false; });
- Example
$('#example2').on('click', function () { $.fn.custombox( this, { effect: 'newspaper' }); return false; });
- Example
$('#example4').on('click', function () { $.fn.custombox( this, { effect: 'slit' }); return false; });
- Example
$('#example5').on('click', function () { $.fn.custombox( this, { open: function () { alert('open'); }, complete: function () { alert('complete'); }, close: function () { alert('close'); } }); return false; });
- Example
$('#example6').on('click', function () { $.fn.custombox( this ); return false; });
- Example
$('#example7').on('click', function () { $.fn.custombox( this, { effect: 'fadein', overlayColor: '#FFF', overlayOpacity: 1, customClass: 'justme', speed: 200 }); return false; });
- Find any bugs? Issues.
- The animations CSS3 based on Codrops.
- This script can run with jQuery.
- The example page is built with Bootstrap 3.
- The page example code is built with SyntaxHighlighter.