window.onload=function(){ var h1=document.getElementById("J_Tzh"); var h2=document.getElementById("J_Guang"); document.getElementById("J_BdSide").style.width='auto'; window.onscroll=function(){ var h=(document.documentElement.scrollTop||document.body.scrollTop)+(document.documentElement.clientHeight||document.body.clientHeight); if(h>=h1.offsetHeight+h2.offsetHeight){ //h2.style.cssText='position: fixed;top: 0;right: 0;'; h2.style.position='fixed'; h2.style.top=(h2-(document.documentElement.clientHeight||document.body.clientHeight))+'px'; h2.style.right=0; }else{ h2.style.position="static"; } } }
用cssText就会出现如下图的问题:
- 用style,就正常。
你是否将样式写在了行间?