To align a div in center vertically using javascript, you can use the following code:
23 chars2 lines
index.tsx142 chars5 lines
In the above code, we first get the div using its ID and then set its position to 'relative'. Then set the top property to '50%', which moves the div down by 50% of its container height. Finally, we use the transform property to move it back up by half of its own height (which centers it vertically).
Note that this will only work if the parent container has a defined height.
gistlibby LogSnag