You can use this CSS:
div.mybox { width: 50px; height: 50px; background-color: red; -webkit-transition:width 300ms ease-in-out, height 300ms ease-in-out; -moz-transition:width 300ms ease-in-out, height 300ms ease-in-out; -o-transition:width 300ms ease-in-out, height 300ms ease-in-out; transition:width 300ms ease-in-out, height 300ms ease-in-out; }
Then you can update the width and height properties with jQuery:
$(document).ready(function() { $("div.mybox").css({"width": "100px", "height": "70px"}); });
So, if the browser supports it, it will be animated. But, of course, consider the possibility of placing these properties in a separate class and adding this class to the element. You can use the .addClass () function like this.
$(document).ready(function() { $("div.mybox").addClass("enlarged"); });
Or, for example, you can use it with the toggleClass function and a click event (the window will be enlarged when pressed, and when pressed again, it will be resized to normal size).
$(document).ready(function() { $("div.mybox").click(function() { $(this).toggleClass("enlarged"); }); });
In this case, the properties must be defined in the CSS class.
div.mybox.enlarged { width: 100px; height: 70px; }
Also, if you want the animation to be performed by mouse, all you need to add is:
div.mybox:hover { width: 100px; height: 70px; }
Animations of this kind can be performed without using JS at all.
In addition, you should read the CSS3 transition attribute and conversion functions (they can be used in many cases). They are described here .