熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

利用腳本封裝,方便實現網站懸浮廣告

2022-06-13   來源: JSP教程 

  下面是JS腳本(floatdivjs)

  /*======================================================================
  浮動塊支持腳本
  DESIGN BY :  彭國輝
  DATE:    
  SITE:    
  EMAIL:    
======================================================================*/

  var alLeft = alCenter = alRight  = ;   //水平對齊方式
var alTop  = alMiddle = alBottom = ;   //垂直對齊方式

  var f = new Array();
var cnt = ;

  function floatDiv(objId align vAlign x y smooth)
{
  /*浮動塊對象
    數據結構
    objId 對象ID
    align 水平對齊方式枚舉型
    vAlign垂直對齊方式枚舉型內容
    x y  xy座標整型
    smooth平滑移動布爾型
  */
  thisobjId  = objId;
  thisalign  = align;
  thisvAlign = vAlign;
  thisx = x;
  thisy = y;
  thissmooth = smooth;
}

  function addDiv(objId align vAlign x y smooth)
{   //添加浮動塊
  f[cnt++] = new floatDiv(objId align vAlign x y smooth);
}

  function floatMove()
{   //重新定位各塊位置
  var objX objY;
  if (documentall)
  {
    var d = documentbody;
//status = scrollLeft:+f[]objIdstylepixelTop+| offsetWidth:+doffsetWidth;
    for (var i=; i<flength; i++)
    {
      switch (f[i]align)
      {
        case alLeft  : objX = dscrollLeft + f[i]x; break;
        case alCenter: objX = dscrollLeft + Mathceil((doffsetWidth f[i]objIdoffsetWidth)/) + f[i]x; break;
        case alRight : objX = dscrollLeft + doffsetWidth f[i]x f[i]objIdoffsetWidth ; break; //減滾動條
      }
      switch (f[i]vAlign)
      {
        case alTop   : objY = dscrollTop + f[i]y; break;
        case alMiddle: objY = dscrollTop + Mathceil((doffsetHeight f[i]objIdoffsetHeight)/) + f[i]y; break;
        case alBottom: objY = dscrollTop + doffsetHeight f[i]y f[i]objIdoffsetHeight; break;
      }
      if (f[i]smooth) smoothMove(f[i]objId objX objY);
      else
      {
        f[i]objIdstylepixelLeft = objX;
        f[i]objIdstylepixelTop  = objY;
      }
    }
  }
  
  if (documentlayers)
  {
    for (var i=; i<flength; i++)
    {
      var objId = f[i]objId;
      switch (f[i]align)
      {
        case alLeft  : objX = pageXOffset + f[i]x; break;
        case alCenter: objX = pageXOffset + Mathceil((windowinnerWidthobjIdwidth)/) + f[i]x; break;
        case alRight : objX = pageXOffset + windowinnerWidth f[i]x documentobjIdwidth; break;
      }
      switch (f[i]vAlign)
      {
        case alTop   : objY = pageYOffset + f[i]y; break;
        case alMiddle: objY = pageYOffset + Mathceil(windowinnerHeight/) + f[i]y; break;
        case alBottom: objY = pageYOffset + windowinnerHeight f[i]y documentobjIdheight; break;
      }
      if (t[i]smooth) smoothMove(f[i]objId objX objY);
      else
      {
        documentobjIdleft = objX;
        documentobjIdtop  = objY;
      }
    }
  }
  
  setTimeout(floatMove(););
}

  function smoothMove(obj x y)
{
  var percent;
  if (documentall)
  {
    percent = * (x objstylepixelLeft);
    if (percent > ) percent = Mathceil(percent); else percent = Mathfloor(percent);
    objstylepixelLeft += percent;
    
    percent = * (y objstylepixelTop);
    if (percent > ) percent = Mathceil(percent); else percent = Mathfloor(percent);
    objstylepixelTop += percent;
  }
  if (documentlayers)
  {
    percent = * (x documentobjIdleft);
    if (percent > ) percent = Mathceil(percent); else percent = Mathfloor(percent);
    documentobjIdleft += percent;
    
    percent = * (y documentobjIdtop);
    if (percent > ) percent = Mathceil(percent); else percent = Mathfloor(percent);
    documentobjIdtop += percent;
  }
}

  setTimeout(floatMove(););

  調用例子

   <script language=javascript src=lib/floatdivjs></script>
<script language=javascript>
if (navigatorappName == Netscape)
{
  documentwrite(<layer id=ad_hr top= width= height=><a href= target=_blank><img src=ad/hrgif width= height= border=></a></layer>);
}
else
{
  documentwrite(<div id=ad_hr style=position: absolute;width:;top:;left:;visibility: visible;zindex: ><a href= target=_blank><img src=ad/hrgif width= height= border=></a></div>);
}
addDiv(ad_hr alRight alTop true);
</script>


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19414.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.