Skip to content

Instantly share code, notes, and snippets.

@corpix
Created March 16, 2012 13:36
Show Gist options
  • Save corpix/2050089 to your computer and use it in GitHub Desktop.
Save corpix/2050089 to your computer and use it in GitHub Desktop.
Increases image size on mouse enter
$(function(){
$('img.expand').each(function(key, el){
var $el = $(el)
, image
, originalWidth, originalHeight
, width, height;
width = $el.attr('width');
height = $el.attr('height');
if(!width || !height)
return;
image = new Image();
image.onload = function(){
originalWidth = image.width;
originalHeight = image.height;
}
image.src = $el.attr('src');
$el.bind('mouseenter mouseleave', function(e) {
$(this).stop().animate({
width: (e.type === 'mouseenter' ? originalWidth : width),
height: (e.type === 'mouseenter' ? originalHeight : height)
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment