Fork me on GitHub
Download

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.

Modern browsers only!

About Custombox:

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.getAttribute('data-' + cb) !== null && parseInt(options.getAttribute('data-' + 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.getAttribute('data-' + cb) !== null && parseInt(options.getAttribute('data-' + 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 ( e ) {
        custombox( this, {
            effect: 'fadein'
        });
        e.preventDefault();
    }, false );
};
</script>

How to use:

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="//code.jquery.com/jquery-1.11.0.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 ( e ) {
        $.fn.custombox( this );
        e.preventDefault();
    });
});
</script>

Settings

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, left and center) | (vertical or horizontal) and output position sseparated by commas. Ex: 'top, bottom'.
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.
responsive true Sets if you like box responsive or not.
scrollbar false Show scrollbar or hide automatically.
error Error 404! Text to be displayed when there is an error.

Public Methods

$.fn.custombox('close') Allow the user to close the modal.

Custom

Without overlay

- Example

$('#example1').on('click', function ( e ) {
    $.fn.custombox( this, {
        overlay: false,
        effect: 'fadein'
    });
    e.preventDefault();
});

Ajax

- Example

$('#example2').on('click', function ( e ) {
    $.fn.custombox( this, {
        effect: 'newspaper'
    });
    e.preventDefault();
});

Auto start

- Example 5

$.fn.custombox({
    url: 'demo/xhr/ajax.html'
});

Error :(

- Example

$('#example4').on('click', function ( e ) {
    $.fn.custombox( this, {
        effect: 'slit'
    });
    e.preventDefault();
});

Callbacks

- Example

$('#example5').on('click', function ( e ) {
    $.fn.custombox( this, {
        open: function () {
            alert('open');
        },
        complete: function () {
            alert('complete');
        },
        close: function () {
            alert('close');
        }
    });
    e.preventDefault();
});

Other style

- Example

$('#example6').on('click', function ( e ) {
    $.fn.custombox( this );
    e.preventDefault();
});

Custom effect 1

- Example

$('#example7').on('click', function ( e ) {
    $.fn.custombox( this, {
        effect:         'fadein',
        overlayColor:   '#FFF',
        overlayOpacity: 1,
        customClass:    'justme',
        speed:          200
    });
    e.preventDefault();
});

Custom effect 2

- Example

The Javascript:
$('#example8').on('click', function ( e ) {
    $.fn.custombox( this, {
        effect:         'slide',
        position:       'center',
        customClass:    'customslide',
        speed:          200
    });
    e.preventDefault();
});
The CSS (Prefix: custombox-show and custombox-close):
.custombox-close.customslide .custombox-modal-content {
    -webkit-transform: scale(2);
    -ms-transform: scale(2);
    transform: scale(2);
    opacity: 1;
    -webkit-transition-property: all;
    -ms-transition-property: all;
    transition-property: all;
}

Custom open and close position.

- Example

$('#example8').on('click', function ( e ) {
    $.fn.custombox( this, {
        effect:     'slide',
        position:   'left, right'
    });
    e.preventDefault();
});

Support:

- Find any bugs? Issues.

Credits:

- 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.