开发者

Centering DIV in javascript

Guys i'm having a problem with the javascript in my website. I cant center the div to properly show the image i click. It only works at the second try, the first try of any image it allways show t开发者_运维技巧he div to the bottom right.

I've tried messing around with the javascript but can't get my head around it.

Check it out here


It happens because you apply the CSS properties before setting the image src.

When you first load an image, there is no previous image and it does nothing to center. When you click another picture, it centers the image according to the previous image's dimensions.


It happens becouse your div doesn't have any offsetWidth and height yet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜