Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animate max-width on img [JQuery]

I have tried looking for a solution, but can't find anything good.

I am customizing a blog for a friend of mine. When it loads, I want all the img's in each post to have a max-width and max-height of 150px. When the user pushes the img, the max-values should increase to 500px, which is easy enough. The problem with my code is that I can't get an animation on it, which I want. Any help out there?

var cssObj = {'max-width' : '500px','max-height' : '500px;'}

$("img").click(function(){     
    $(this).css(cssObj); 
}); 
like image 777
Øyvind Avatar asked Mar 22 '26 16:03

Øyvind


2 Answers

I got it working, combining two of the other answers (and removing max-width & max-height in the css-code)

var cssBegin = {'max-width' : '250px','max-height' : '250px;'};       
$('img').css(cssBegin);     
var cssObj = {'max-width' : '500px','max-height' : '500px;'};
 $("img").click(function(){          $(this).animate(cssObj,'slow');  });  
like image 151
Øyvind Avatar answered Mar 25 '26 05:03

Øyvind


instead of using .css(), try using .animate()

var cssObj = {'max-width' : '500px','max-height' : '500px;'}

$("img").click(function(){     
    $(this).animate(cssObj,'slow'); 
}); 
like image 40
jondavidjohn Avatar answered Mar 25 '26 05:03

jondavidjohn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!