Vous pourriez faire quelque chose comme ça, en utilisant .height()
et .width()
avec des arguments de fonction:
$("img").hover(function() {
$(this).height(function(i, h) { return h * 1.2; })
.width(function(i, w) { return w * 1.2; });
}, function() {
$(this).height(function(i, h) { return h/1.2; })
.width(function(i, w) { return w/1.2; });
});
You can give it a try here, si vous vouliez une animation fluide, vous pouvez stocker la première ight/largeur et .animate()
, comme ceci:
$("img").each(function() {
$.data(this, 'size', { width: $(this).width(), height: $(this).height() });
}).hover(function() {
$(this).stop().animate({ height: $.data(this,'size').height*1.2,
width: $.data(this,'size').width*1.2 });
}, function() {
$(this).stop().animate({ height: $.data(this,'size').height,
width: $.data(this,'size').width });
});
You can give it a try here, assurez-vous d'exécuter une ou l'autre de ces options $(window).load()
et pas$(document).ready()
, puisque les dimensions peuvent ne pas être encore chargés.
cool, Cheers mate – Dancer