Choan C. Gálvez schrieb:
> On 10/24/06, Truppe Steven <[EMAIL PROTECTED]> wrote:
>> i'm using the center plugin to center images inside a div. But i have to
>> call it with a timeout like this:
>>
>> $(document).ready(function(){
>> setTimeout("doCenter()",1000);
>> });
>>
>> function doCenter(){
>> $(".jqcenter").each(){
>> $(this).center();
>> }
>> }
>>
>>
>> I do not really understand why i need a timeout here because DOM should
>> allready be ready inside of $(document).ready().
>
> That's correct.
>
>> The Problem with this is that it fails for some reason in certain cases,
>> so that the image is misplaced. To me it looks like that in these cases
>> the function is called to early because if i refresh the page it look fine.
>>
>> If i replace setTimeOut and call the function direct with doCenter() it
>> does not work at all.
>> Do i have a general understanding problem or what am i doing wrong ?
>
> While the DOM is complete when `ready` fires, the images may not have
> completely loaded, so you cannot access its dimensions. When you
> refresh the page, the images are already in the cache.
>
> So, while `document.ready` is what we want in 99,9% of the cases, it
> seems it's not in yours.
>
> Go with `$(window).load`.
>
Centering an image? Why not using little CSS and you are done...:
img {
display: block;
margin: 0 auto;
}
Or if you leave the element as inline element and a have a container for
the image:
div {
text-align: center;
}
-- Klaus
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/