怎么样使一个层居中(在各种分辨率下?)

怎么样使一个层居中(在各种分辨率下?)
---------------------------------------------------------------

Y=document.clientheight
X=document.clientwidth
layerY = layer.height
layerX = layer.width
在window.onload里面指定
layer.top = (Y-layerY)/2
layer.left = (X-layerX)/2
当然,如果您的窗口有滚动条,应该减去document.scrolingTop(好象是这个属性,没时间查了,包涵)
---------------------------------------------------------------

好像可以用相对定位来实现这个。
你可以把层放到一个屏幕中居中的元素里,再把层的L:的值delete掉。
好像可以。
---------------------------------------------------------------

弄一个层吧,且唤之divBG
还是习惯用VBS,自己看着办吧

 1<script id="clientEventHandlersVBS" language="vbscript">   
 2<!--   
 3option explicit   
 4  
 5sub posInit   
 6  
 7dim intLeft   
 8intLeft=(document.body.offsetWidth -divBG.style.posWidth )/2   
 9if intLeft>0 then   
10divBG.style.posLeft =intLeft   
11else   
12divBG.style.posLeft =0   
13end if   
14  
15end sub   
16  
17Sub window_onload   
18  
19call posInit   
20  
21End Sub   
22  
23Sub window_onresize   
24  
25call posInit   
26  
27End Sub   
28  
29\-->   
30</script>
Published At
Categories with Web编程
comments powered by Disqus