对于使用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()中定义。