Skip to content

Instantly share code, notes, and snippets.

@skunkworker
Created August 5, 2015 18:03
Show Gist options
  • Save skunkworker/809059ba8d9b919ec769 to your computer and use it in GitHub Desktop.
Save skunkworker/809059ba8d9b919ec769 to your computer and use it in GitHub Desktop.
Multiple Bootstrap modals
$(document).ready(function() {
$('#openBtn').click(function(){
$('#myModal').modal({show:true})
});
$('.modal').on('hidden.bs.modal', function( event ) {
$(this).removeClass( 'fv-modal-stack' );
$('body').data( 'fv_open_modals', $('body').data( 'fv_open_modals' ) - 1 );
});
$( '.modal' ).on( 'shown.bs.modal', function ( event ) {
// keep track of the number of open modals
if ( typeof( $('body').data( 'fv_open_modals' ) ) == 'undefined' )
{
$('body').data( 'fv_open_modals', 0 );
}
// if the z-index of this modal has been set, ignore.
if ( $(this).hasClass( 'fv-modal-stack' ) )
{
return;
}
$(this).addClass( 'fv-modal-stack' );
$('body').data( 'fv_open_modals', $('body').data( 'fv_open_modals' ) + 1 );
$(this).css('z-index', 1040 + (10 * $('body').data( 'fv_open_modals' )));
$( '.modal-backdrop' ).not( '.fv-modal-stack' ).css( 'z-index', 1039 + (10 * $('body').data( 'fv_open_modals' )));
$( '.modal-backdrop' ).not( 'fv-modal-stack' ).addClass( 'fv-modal-stack' );
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment