Last active
December 17, 2015 00:49
-
-
Save Dare-NZ/5523429 to your computer and use it in GitHub Desktop.
A super simple lightweight jQuery lightbox function that accepts any HTML. May need some cross browser adjustments.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
utilCreateLightbox : function(new_options) { | |
options = { | |
box_class : '', | |
box_content : '', | |
wrap_css : { | |
position : 'fixed', | |
left : 0, | |
top : 0, | |
width : '100%', | |
height : '100%', | |
background : '#000', | |
background : 'rgba(255,255,255,0.9)', | |
'z-index' : 999999 | |
}, | |
table_css : { | |
display : 'table', | |
width : '100%', | |
height : '100%' | |
}, | |
row_css : { | |
display : 'table-row' | |
}, | |
cell_css : { | |
display : 'table-cell', | |
'text-align' : 'center', | |
'vertical-align' : 'middle' | |
}, | |
box_css : { | |
display : 'inline-block', | |
'*display' : 'inline', | |
width : 'auto', | |
height : 'auto', | |
position : 'relative', | |
padding : '20px', | |
border : '1px solid #e6e6e6', | |
background : '#fff' | |
} | |
}; | |
$.extend(true, options, new_options); | |
$lightbox_wrap = $('<div class="lightbox-wrap" />').appendTo('body'); | |
$lightbox_table = $('<div class="lightbox-table" />').appendTo($lightbox_wrap); | |
$lightbox_row = $('<div class="lightbox-row" />').appendTo($lightbox_table); | |
$lightbox_cell = $('<div class="lightbox-cell" />').appendTo($lightbox_row); | |
$lightbox_box = $('<div class="lightbox-box" />').appendTo($lightbox_cell); | |
$lightbox_wrap.css(options.wrap_css); | |
$lightbox_table.css(options.table_css); | |
$lightbox_row.css(options.row_css); | |
$lightbox_cell.css(options.cell_css); | |
$lightbox_box.css(options.box_css); | |
$lightbox_box.addClass(options.box_class); | |
$lightbox_box.html(options.box_content); | |
$('.lightbox-cell').on('click', function(e) { | |
if(e.target == this){ | |
$('.lightbox-wrap').fadeOut(1000, function() { | |
$('.lightbox-wrap').remove(); | |
}); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to use an options object, so all css can be customised