Skip to content

Instantly share code, notes, and snippets.

@benfoxall
Created January 13, 2010 11:32
Show Gist options
  • Save benfoxall/276124 to your computer and use it in GitHub Desktop.
Save benfoxall/276124 to your computer and use it in GitHub Desktop.
minimal image enlarge
// intercept rel=image clicks and make images fade in over the top
$$('a[rel=image]').each(function(link){
link.observe('click',function(e){
Event.stop(e);
i = new Element('img');
i.observe('load',function(){
$('image_mask').appear()
})
// do this afterwards for IE
i.writeAttribute('src',$(this).readAttribute('href'));
$('image_mask').update(i);
}.bindAsEventListener(link))
})
//hide the image when the page is clicked
$('image_mask').observe('click',function(){
$('image_mask').fade({afterFinish:function(){
//once hidden, remove it
$('image_mask').update('');
}})
})
<div id="image_mask" style="display:none"></div>
<a href="the-image.jpg" rel="image"><img src="the-thumbnail.jpg" /></a>
#image_mask {
text-align:center;
background-color:#fff;
width:100%;
height:100%;
position:absolute;
}
#image_mask img{
margin:auto;
padding: 40px 0 40px 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment