Roughly: - get the width, height, top and left of the parent (width(), height() and offset()) - get the width and height of the child - calculate top and left of the child (simple maths) - set the top and left of the child according to the calculated values above (css()) - fade in child (fadeIn())
The above are not fixed in stone because it *very much* depends on what else is going on around the divs in question, whether there is other content in parent, and how the divs are 'position'ed (static, relative, absolute). For example, if parent is empty except for child, then you could vary the parent's padding, or the child's margins, to centre the child. If parent is relative and has other content that child will cover, then child will be absolute and the above applies. On the other hand, if parent is static (with other content) then you will have to position the absolute child according to the next non- static element up the DOM. Alternatively, if both never change in size, use styles to position them and simply fade in child when needed. There are too many variables/unknowns to be able to give a definitive answer. On Nov 22, 10:06 pm, shapper <[EMAIL PROTECTED]> wrote: > Hello, > > I have 2 divs: > > <div id="parent"> > <div id="child"> > </div> > </div> > > I need to create a function using JQuery that when called does the > following: > 1. Centers child inside parent > 2. Fades in child > > How can I do this? > > Thanks, > Miguel