开发者

DIVs with style.display none still showing up

on loading a page I have some javascript code which hides some layers

document.getElementById(layerName).style.display = "none";

Everything work开发者_Python百科s well, but in IE and in Opera these DIVs are showing up for the first few milliseconds while the page loads. After that, it's back to normal.

Is there a way around that?

Thanks!


If you run code when the page loads, it will not run until the page finishes loading.

Instead, you can put the code in a <script> block below the elements, without handling onload.

Or you just use CSS.


you could set display to false in you HTML code


Is there a way around that?

It's called CSS:

.layer {
display:'none';
}

This problem occurs because of the way the browser renders the page. CSS is first before Javascript. So always try to do things in CSS when possible.


place this script immediately below the div placed. you will almost clear the problem

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜