⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 layerlib.js

📁 这是我卖的书上的源码 这书是电子邮电出版的是有关网络编程 有详细的例子
💻 JS
字号:
/* layerlib.js: Simple Layer library with basic 
   compatibility checking */

/* detect objects */
var layerobject = ((document.layers) ? (true) : (false));
var dom = ((document.getElementById) ? (true) : (false));
var allobject = ((document.all) ? (true) : (false));

/* detect browsers */
opera=navigator.userAgent.toLowerCase().indexOf('opera')!=-1;

/* return the object for the passed layerName value */
function getElement(layerName,parentLayer) 
{

 if(layerobject)
  {
    parentLayer = (parentLayer)? parentLayer : self;
    layerCollection = parentLayer.document.layers;
    if (layerCollection[layerName])
      return layerCollection[layerName];
    /* look through nested layers */
    for(i=0; i < layerCollection.length;)
      return(getElement(layerName, layerCollection[i++]));
  }
     
  if (allobject)
    return document.all[layerName];
     
  if (dom)
    return document.getElementById(layerName); 
}

/* hide the layer with id = layerName */
function hide(layerName)
{
   var theLayer = getElement(layerName);
   if (layerobject)
     theLayer.visibility = 'hide';
   else
     theLayer.style.visibility = 'hidden';
}

/* show the layer with id = layerName */
function show(layerName)
{
   var theLayer = getElement(layerName);
   if (layerobject)
     theLayer.visibility = 'show';
   else
     theLayer.style.visibility = 'visible';
}

/* set the x-coordinate of layer named layerName */
function setX(layerName, x) 
{
   var theLayer = getElement(layerName);
   if (layerobject)
     theLayer.left=x;
   else if (opera)
     theLayer.style.pixelLeft=x;
   else  
     theLayer.style.left=x+"px";
} 

/* set the y-coordinate of layer named layerName */
function setY(layerName, y) 
{
   var theLayer = getElement(layerName);
   
   if (layerobject)
     theLayer.top=y;
   else if (opera)
     theLayer.style.pixelTop=y;
   else  
     theLayer.style.top=y+"px";
}

/* set the z-index of layer named layerName */
function setZ(layerName, zIndex) 
{
   var theLayer = getElement(layerName);

   if (layerobject)
     theLayer.zIndex = zIndex;
   else
     theLayer.style.zIndex = zIndex;
} 

/* set the height of layer named layerName */
function setHeight(layerName, height) 
{
   var theLayer = getElement(layerName);

   if (layerobject)
     theLayer.clip.height = height;
   else if (opera)
     theLayer.style.pixelHeight = height;
   else
     theLayer.style.height = height+"px";
}

/* set the width of layer named layerName */
function setWidth(layerName, width) 
{
  var theLayer = getElement(layerName);

  if (layerobject)
     theLayer.clip.width = width;
  else if (opera)
     theLayer.style.pixelWidth = width;
  else
     theLayer.style.width = width+"px";
}

/* set the clipping rectangle on the layer named layerName
   defined by top, right, bottom, and left */
function setClip(layerName, top, right, bottom, left) 
{
   var theLayer = getElement(layerName);

   if (layerobject)
     {
        theLayer.clip.top = top;
        theLayer.clip.right = right;
        theLayer.clip.bottom = bottom;
        theLayer.clip.left = left;
     }
   else
     theLayer.style.clip = "rect("+top+"px "+right+"px "+" "+bottom+"px "+left+"px )";

}

/* set the contents of layerName to passed content*/
function setContents(layerName, content)
{
   var theLayer = getElement(layerName);

   if (layerobject)
     {
       theLayer.document.write(content);
       theLayer.document.close();
       return;
     }

   if (theLayer.innerHTML)
      theLayer.innerHTML = content;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -