Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript jQuery Vertically Center Content Re: jQuery Vertically Center Content

#103169

Moving the script to the bottom of the document (just before the closing body tag) should fix the issue. From my limited understanding, it is running the script before the image element has been drawn, and that is what is causing the issue (which is why the margin top and left values are 0, as the image has no height or width until it has been drawn).

EDIT: The other thing that should fix it would be to wrap the jQuery in the following:

$(document).ready( function() {

});

This would stop the code from running until the page is loaded, but I believe placing scripts at the bottom of the document is best for page load times.