【发布时间】:2012-01-30 19:57:36
【问题描述】:
对于使用 jQuery 的网站,页面上有图形,当点击这些图形时,会在网站的另一部分显示信息。当鼠标悬停时,图像会从它们的中心扩大一个百分比。问题是当您快速进出鼠标时(在动画完成之前),图像无法正确调整大小。 (它们变小了。)
$(".locationimg").hover(
function(){
var height = $(this).height()
var width = $(this).width()
var top = $(this).position().top
var left = $(this).position().left
$(this).stop().animate({
height: height*1.1 + 'px',
width: width*1.1 + 'px',
top: top - (((height*1.1)-height)/2) + 'px',
left: left - (((width*1.1)-width)/2) + 'px'
});
},
function(){
var height = $(this).height()
var width = $(this).width()
var top = $(this).position().top
var left = $(this).position().left
var height1 = height/1.1
var width1 = width/1.1
$(this).stop().animate({
height: height1 + 'px',
width: width1 + 'px',
top: top - (((height1)-height)/2) + 'px',
left: left - (((width1)-width)/2) + 'px'
});
}
);
如果可以在进入 .hover() 之前定义变量,这将很容易,因为调整图像大小将只是“高度:高度”等等。这样做的问题是有几个图像都需要这样做,因此需要在 .hover() 中定义变量。
【问题讨论】:
标签: jquery resize hover jquery-animate var