I have a div that covers the entire page width=100% and height=100%. I want usign jquery.animate to animate the div to horizontally center with a smaller width i.e 800px
I have a div that covers the entire page width=100% and height=100% . I
Share
It all depends on your CSS and how flexible you are.
Here is an example of one way to do it:
http://jsfiddle.net/2Qxwn/
In this case, I position the
divrelative, and use jQuery to set the initial height/width to the width of the document. I also set theleftposition to 50%, and themargin-leftto half of the width (thus pulling it back to center). I then animate thewidthand themargin-leftaccordingly.You can also use the
margin: automethod of centering, and then you only have to animate the width, but I am always leery of this method of centering:http://jsfiddle.net/2Qxwn/1/