Created
May 6, 2013 11:05
-
-
Save Dare-NZ/5524530 to your computer and use it in GitHub Desktop.
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
function createLightbox(lightbox_content, lightbox_class) { | |
$('body').append('<div class="lightbox-wrap" ><div class="lightbox-position"><div class="lightbox ' + lightbox_class + '" /></div></div>'); | |
$lightbox = $('.lightbox'); | |
$lightbox_position = $('.lightbox-position'); | |
$lightbox_wrap = $('.lightbox-wrap'); | |
$lightbox_wrap.css({ | |
position : 'fixed', | |
left : 0, | |
top : 0, | |
width : '100%', | |
height : '100%', | |
background : '#000', | |
background : 'rgba(0,0,0,0.5)', | |
'z-index' : 999999 | |
}); | |
$lightbox_position.css({ | |
position : 'fixed', | |
right : 0, | |
bottom : 0, | |
width : '50%', | |
height : '50%', | |
'pointer-events':'none' | |
}); | |
$lightbox.css({ | |
position : 'absolute', | |
left : '-99999px', | |
top : '-99999px', | |
width : 'auto', | |
height : 'auto', | |
padding : '20px', | |
background : '#fff', | |
border : '1px solid #ddd' | |
}); | |
$lightbox.append(lightbox_content); | |
var top_offset = -1 * ($lightbox.outerHeight() / 2); | |
var left_offset = -1 * ($lightbox.outerWidth() / 2); | |
$lightbox.css({ | |
left : left_offset, | |
top : top_offset | |
}); | |
$('.lightbox-wrap').live('click', function(e) { | |
if(e.target == this){ | |
$(this).fadeOut(500, function() { | |
$(this).remove(); | |
}); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment