-
-
Save ryankinal/3091587 to your computer and use it in GitHub Desktop.
$(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> |
This is actually pretty inefficient code. There's plenty that could be done outside of the click handler.
Yeah, I've done a little with Mustache. The thing that probably intrigues me the most is the fact that I could use the same templating engine on the client side (JS) and on the server side (PHP). I've still mostly stuck with Smarty, but I'd like to give Mustache another look.
Also, I've added another, slightly more efficient version of this lightbox.
http://www.mckissock.com/real-estate/florida/default.aspx
"Request a FREE Info Kit" or "Watch the Video"
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.
+1