You can achieve this effect while animating the top and height. You just need to determine the final height.
For example, if you have:
#mydiv{
top: 200px;
height: 300px;
width: 100px;
background-color: red;
position: absolute;
};
and you want to end with an animated div:
#mydiv{
top: 0px;
height: 500px;
width: 100px;
background-color: red;
position: absolute;
};
jquery code when you click div:
$("#mydiv").on("click", function(){
$('#mydiv').animate( {"top": "0px", "height": "500px" } );
});
source
share