(function($) { $.fn.cbZoom = function() { return this.each(function() { var x = 0; var y = 0; var xSpeed = 0; var ySpeed = 0; bigImage = $(''); bigImage.bind('load', function() { xSpeed = $(this).parent().width() / ($(this).width() - $(this).parent().width()); ySpeed = $(this).parent().height() / ($(this).height() - $(this).parent().height()); $(this).css({ position: 'absolute' }).hide(); }); smallImage = $(this).children('img'); smallImage.bind('load', function() { $(this).parent().css({ width: $(this).width(), height: $(this).height() }); $(this).parent().append(bigImage); bigImage.attr('src', $(this).parent().attr('href')); }); $(this).mouseenter(function() { return false; }).mousemove(function(event) { x = event.pageX - $(this).offset().left; y = event.pageY - $(this).offset().top; bigImage.css({ left: (x / xSpeed * -1), top: (y / ySpeed * -1) }); }).mouseleave(function() { bigImage.fadeOut(); }).click(function() { bigImage.fadeIn(); return false; }); }); }; })(jQuery);