Since you want to learn how to do this, here is a relatively simple example. The code is below and also posted to this pastebin.
Note: The script assumes that the thumbnail and full-sized image are the same. You can store the full size image URL in the image rel
attribute if it is different. Then just change the popupImage src to this: $(this).find('img').attr('rel')
CSS
#overlay {
position: absolute;
left: 0;
top: 0;
height: 100%;
width: 100%;
background: #000;
opacity: 0.8;
filter: alpha(opacity=80);
}
#popupImage {
position: absolute;
left: -99999px;
top: 0;
}
HTML example
<a class="cell"><img src="http://i47.tinypic.com/2m2c36v.jpg" width="30" /></a>
Script
$(document).ready(function(){
$('a.cell').click(function(){
// Add overlay
$('<div id="overlay" />')
.hide()
.appendTo('body')
.fadeIn('slow');
// Add image & center
$('<img id="popupImage" src="' + $(this).find('img').attr('src') + '">').appendTo('body');
var img = $('#popupImage');
var imgTop = ($(window).height() - img.height())/2;
var imgLft = ($(window).width() - img.width())/2;
img
.hide()
.css({ top: imgTop, left: imgLft })
.fadeIn('slow');
// Add click functionality to hide everything
$('#overlay,#popupImage').click(function(){
$('#overlay,#popupImage').fadeOut('slow',function(){
$(this).remove();
$('#overlay').remove();
});
})
});
})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…