2013-05-17 48 views
0

我有这个脚本可以放大悬停时的图像缩略图。如何在使用jQuery保持尺寸的同时调整图像大小?

问题是,一些图像是不同的高度,所以脚本有时会伸展它们不成比例。大部分图像是100×100,但有时他们是100x140,等

有没有办法保存在调整图像的尺寸?

$("ul.gallery-large li").hover(function() { 
$(this).find('img').addClass("hover").stop() 
    .animate({ 
    width: '200px', 
    height: '200px', 
}, 200); 

}, function() { 
$(this).find('img').removeClass("hover").stop() 
    .animate({ 
    width: '100px', 
    height: '100px' 
}, 400); 
}); 

回答

1

你可以尝试:

$("ul.gallery-large li").hover(
    function() { 
     $(this).find('img').addClass("hover") 
      .animate({width: '200px'}, 200); 
    }, function() { 
     $(this).find('img').removeClass("hover") 
      .animate({width: '100px'}, 400); 
    } 
); 

和CSS:

ul.gallery-large li img{height:auto} 

这是工作:http://jsfiddle.net/dxFq6/1/

+0

感谢。周末愉快 :) – Gaillimh

相关问题