我在jQuery中使用此代码来放大或卸载HOVER上的图像(图像)。jQuery在MouseOver/MouseOut上放大/缩小特定图像
该脚本效果很好,除此之外,如果用户快速移动和移出图像上的光标,脚本会不断放大图像。
所以我想避免这种情况,并有一个方法来正确地停止动画。任何想法如何解决这个问题?非常感谢!
// Enlarge/Shrink a specific image on MouseOver/MouseOut
$('#photos').find('img').hover(function() {
// Get size for selecte image
$this = $(this);
originalWidth = $this.width();
originalHeight = $this.height();
scale = 20;
speed = 250;
newWidth = originalWidth + originalWidth/100*scale;
newHeight = originalHeight + originalHeight/100*scale;
$this.animate({ // Enlarge image on MouseOver
width : newWidth,
height : newHeight
},speed);
}, function() { // Shrink image on MouseOut
$this.animate({
width : originalWidth,
height: originalHeight
},speed);
}); // end hover