刘珂的博客

javascript控制div或者弹出窗口到屏幕中央以及loading

分类:js  人气:524  评论:0  时间:2009-12-08 15:51
 
sshong 发表于2008-05-22 19时02分 更新于2008-06-10 18时21分
以下是找到的资料。

<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)
标签(Tag):js
评论(0)
暂无评论
我来评论
(800字以内)
博客分类
最新阅读用户
暂无用户