Edit: For your below comment,
Thanks. However, it requires a right-click on the picture. it does not
work if you keep the right button down somewhere else in the screen
and then pass the image
You need to add mouseup event and zoom conditionally. See below code, DEMO
var hasExpanded = false;
$('img').on('mousedown mouseup', function(e) {
if (e.which == 3) {
if (!hasExpanded) {
$(this).animate({
width: $(this).width() * 2,
height: $(this).height() * 2,
}, 500);
}
hasExpanded = true;
}
}).mouseleave(function(e) {
if (hasExpanded == true) {
$(this).animate({
width: $(this).width() / 2,
height: $(this).height() / 2,
}, 500);
hasExpanded = false;
}
});
What you need cannot be achieved through hover. Hover will be triggered on mouseeneter which will be called only once and It cannot record the mousedown event which happens at later point.
You need to implement mousedown handler. See below,
DEMO - Demo has both mousedown and mouseleave implemented.
$('img').mousedown(function(e) {
if (e.which == 3) {
$(this).animate({
width: $(this).width() * 2,
height: $(this).height() * 2,
}, 500);
}
});