var s = ""; s += " 网页可见区...ather shu,web工程师,专注但不局限于flash、html5、js、php等web领域。">
javascript控制div或者弹出窗口到屏幕中央以及loading
sshong 发表于2008年5月22日 19:02:00 更新于2008年6月10日 18:21:00
以下是找到的资料。
<SCRIPT LANGUAGE="JavaScript">
var  s = "";
s += " 网页可见区域宽:"+ document.body.clientWidth;
s += " 网页可见区域高:"+ document.body.clientHeight;
s += " 网页可见区域宽:"+ document.body.offsetWidth  +" (包括边线和滚动条的宽)";
s += " 网页可见区域高:"+ document.body.offsetHeight +" (包括边线的宽)";
s += " 网页正文全文宽:"+ document.body.scrollWidth;
s += " 网页正文全文高:"+ document.body.scrollHeight;
s += " 网页被卷去的高:"+ document.body.scrollTop;
s += " 网页被卷去的左:"+ document.body.scrollLeft;
s += " 网页正文部分上:"+ window.screenTop;
s += " 网页正文部分左:"+ window.screenLeft;
s += " 屏幕分辨率的高:"+ window.screen.height;
s += " 屏幕分辨率的宽:"+ window.screen.width;
s += " 屏幕可用工作区高度:"+ window.screen.availHeight;
s += " 屏幕可用工作区宽度:"+ window.screen.availWidth;
s += " 你的屏幕设置是 "+ window.screen.colorDepth +" 位彩色";
s += " 你的屏幕设置 "+ window.screen.deviceXDPI +" 像素/英寸";
alert(s);
</SCRIPT>

1.弹出窗口到屏幕中央
    function openBrWindowInCentre(theURL,width,height) {
      var left, top;
      left = (window.screen.availWidth - width) / 2;
      top = (window.screen.availHeight - height) / 2;
      var per = 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',screenX=' + left + ',screenY=' + top;
      window.open(theURL,'',per);
    }

2.控制div在屏幕中央
a.
<DIV ID="oDiv" STYLE="background-color:   #CFCFCF;   position:   absolute; left:expression(document.body.clientWidth/2-oDiv.offsetWidth/2); top:expression(((document.body.clientHeight/2-oDiv.offsetHeight/2)<0)?0:(document.body.clientHeight/2-oDiv.offsetHeight/2))">
b.
<script   language="javascript">  
  function   switchSpan(spanId)
{  
  if(document.all[spanId].style.visibility=="visible")  
     document.all[spanId].style.visibility="hidden";  
  else
  {  
    document.all[spanId].style.visibility="visible";  
    document.all[spanId].style.left=document.body.scrollLeft+document.body.offsetWidth/2-315;
    document.all[spanId].style.top=document.body.scrollTop+document.body.offsetHeight/2-76;
  }  
}  
</script>
<script   language="JavaScript">  
var   dragapproved=false;
var   z,x,y ;
function   move()
{  
  if(event.button==1&&dragapproved)
  {  
     z.style.pixelLeft=temp1+event.clientX-x;
     z.style.pixelTop=temp2+event.clientY-y;
     return false;
   }
}  
function drags()
{  
  if (!document.all)  
  return;
  if (event.srcElement.className=="drag")
  {  
   dragapproved=true;  
   z=event.srcElement  
   temp1=z.style.pixelLeft;
   temp2=z.style.pixelTop;    
   x=event.clientX;  
   y=event.clientY;  
   document.onmousemove=move;
  }
}  
document.onmousedown=drags  
document.onmouseup=new  Function("dragapproved=false");
</script>  
3.网页loading
function loadBar(fl)
{
  //fl is show/hide flag  
  var x,y;
  if (self.innerHeight)
  {
    // all except Explorer
    x = self.innerWidth;
    y = self.innerHeight;
  }
  else if (document.documentElement && document.documentElement.clientHeight)
  {
    // Explorer 6 Strict Mode
    x = document.documentElement.clientWidth;
    y = document.documentElement.clientHeight;
  }
  else
  if (document.body)
  {
    // other Explorers
    x = document.body.clientWidth;
    y = document.body.clientHeight;
  }
  var el=document.getElementById('loader');
  if(null != el)
  {
    var top = (y/2) - 50;
    var left = (x/2) - 200;
    if( left<=0 ) left = 10;
    el.style.visibility = (fl==1)?'visible':'hidden';
    el.style.display = (fl==1)?'block':'none';
    el.style.left = left + "px"
    el.style.top = top + "px";
    el.style.zIndex = 2;
  }
}
在body的onload里loadBar(0),在loader这个div后面调用js的loadBar(1)
标签:jsloading屏幕中央分类:未分组阅读:7623
评论
AS2008年5月22日 21:29
用一晚上的时间上发现一个js的cookie在获取参数的时候因为有一个空格问题,就是两个参数间有一个;和一个空格,还有就是setcookie的时候要一个一个参数添加,不能一次等于
name=sshong; id=9; expires=***,我狂晕阿
js2008年5月22日 19:25
我来嵌入js,哈哈
<Script language="javascript">
alert("good");
</Script>
添加评论
您的大名,限长10汉字,20英文(*)
电子信箱(*)
您的网站
正文,限长500汉字,1000英文(*)
验证码(*) 单击刷新验证码
联系我
博客订阅