Skip to content

Instantly share code, notes, and snippets.

@ryankinal
Created July 11, 2012 16:35
Show Gist options
  • Select an option

  • Save ryankinal/3091587 to your computer and use it in GitHub Desktop.

Select an option

Save ryankinal/3091587 to your computer and use it in GitHub Desktop.
Really friggin' simple jQuery lightbox
$(function() {
var $blanket = $('#blanket'),
$close = $('#lightboxClose');
if ($blanket.size() === 0)
{
$blanket = $('<div />', {id: 'blanket'}).css({
'position': 'fixed',
'left': '0',
'top': '0',
'width': $(document).width() + 'px',
'height': $(document).height() + 'px',
'display': 'none'});
$('body').append($blanket);
}
if ($close.size() === 0)
{
$close = $('<div />', {id: 'lightboxClose', 'class': 'png'});
}
$(document).delegate('a[rel="lightbox"]', 'click', function() {
var href = this.href,
id = href.substring(href.lastIndexOf('#')),
$div = $(id);
if ($div.size() > 0)
{
$blanket.fadeTo(1000, 0.9);
$div.appendTo('body').fadeIn(600).css({
'position': 'fixed',
'left': '50%',
'top': '50%',
'margin-left': (($div.width() / 2) * -1) + 'px',
'margin-top': (($div.height() / 2) * -1) + 'px'
});
$close.appendTo($div).one('click', function() {
$blanket.fadeOut(600);
$div.fadeOut(600);
$blanket.unbind('click');
});
$blanket.one('click', function() {
$blanket.fadeOut(600);
$div.fadeOut(600);
$close.unbind('click');
});
}
return false;
});
});
<a href="#yourID" rel="lightbox">Link</a>
<div id="yourID">
<!--- content -->
</div>
@tchalvak

tchalvak commented Jul 31, 2012 via email

Copy link
Copy Markdown

@tchalvak

tchalvak commented Jul 31, 2012 via email

Copy link
Copy Markdown

@ryankinal

Copy link
Copy Markdown
Author

http://www.mckissock.com/real-estate/florida/default.aspx

"Request a FREE Info Kit" or "Watch the Video"

@tchalvak

tchalvak commented Jul 31, 2012 via email

Copy link
Copy Markdown

@tchalvak

tchalvak commented Sep 4, 2012

Copy link
Copy Markdown

By the way, I'm trying out mustache templates in php, and while they really really simplify the templates, I wouldn't really recommend going in that direction on any substantial project where anyone other than yourself is going to work with the templates. Complicates things more than necessary, I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment