var h=0;
var w=0;
$(".extend").hover(function() {
//alert(h);
$(this).css({'z-index' : '999' });
$(this).addClass("hover").filter(":not(:animated)").stop()
.animate({
marginTop: '-110px',
marginLeft: '10px',
top: '80%',
left: '80%',
width: 387,
height: 487,
padding: '0px'
}, 200);
h=$(this).height();
w=$(this).width();
} , function() {
$(this).css({'z-index' : '0'});
$(this).removeClass("hover").stop()
.animate({
marginTop: '0',
marginLeft: '0',
top: '0',
left: '0',
width:w,
height:h,
padding: '0px'
}, 400);
});
<img class="extend" src="a.jpg">
<img class="extend" src="b.jpg">
I have problem with my hover function i can’t make the image back to original size if i hover it to a.jpg it expand then i hover over to b.jpg without waiting a.jpg to return to original size it will become bigger and bigger.
How i can hover and expand without shifting the size?
Unless you need your width and height to change, you should only set it once, assuming both images are the same size this should work
FIDDLE
EDIT–
For images with different dimensions save them in the element using .data()
FIDDLE
EDIT-2-
A simple way to solve the shifting problem is to wrap the img tags in an inline-block element, set the elements dimensions to that of the image then make the img absolutly positioned
FIDDLE