Below is the JS script (floatdiv. JS)
/* ===================================================== ======================================
Floating block support script
Design by: Peng Guohui
Date: 2004-02-26
Site: http://kacarton.yeah.net/
Blog: http://blog.csdn.net/nhconch
Email: kacarton@sohu.com
The article is original to the author. Please contact me before reprinting. for reprinting, please indicate the source of the article and retain the author information. Thank you for your support!
========================================================== ===================================== */
VaR alleft = 0, alcenter = 1, alright = 2; // Horizontal Alignment
VaR altop = 0, almiddle = 1, Albottom = 2; // Vertical Alignment
VaR F = new array ();
VaR CNT = 0;
Function floatdiv (objid, align, valign, X, Y, smooth)
{
/* Floating block object
Data structure:
Objid: Object ID
Align: horizontal alignment, enumeration type
Valign: vertical alignment, enumeration content
X, Y: XY coordinate, integer
Smooth: smooth movement, Boolean
*/
This. objid = objid;
This. align = align;
This. valign = valign;
This. x = X;
This. Y = y;
This. Smooth = smooth;
}
Function adddiv (objid, align, valign, X, Y, smooth)
{// Add floating block
F [CNT ++] = new floatdiv (objid, align, valign, X, Y, smooth );
}
Function floatmove ()
{// Locate the location of each block
VaR objx, objy;
If (document. All)
{
VaR d = Document. Body;
// Status = "scrollleft:" + F [0]. objid. style. pixeltop + "| offsetwidth:" + D. offsetwidth;
For (VAR I = 0; I <F. length; I ++)
{
Switch (F [I]. Align)
{
Case alleft: objx = D. scrollleft + F [I]. X; break;
Case alcenter: objx = D. scrollleft + math. Ceil (D. offsetwidth-f [I]. objid. offsetwidth)/2) + F [I]. X; break;
Case alright: objx = D. scrollleft + D. offsetwidth-f [I]. X-f [I]. objid. offsetwidth-20; break; // subtract the scroll bar 20
}
Switch (F [I]. valign)
{
Case altop: objy = D. scrolltop + F [I]. Y; break;
Case almiddle: objy = D. scrolltop + math. Ceil (D. offsetheight-f [I]. objid. offsetheight)/2) + F [I]. Y; break;
Case Albottom: objy = D. scrolltop + D. offsetheight-f [I]. Y-f [I]. objid. offsetheight; break;
}
If (F [I]. Smooth) smoothmove (F [I]. objid, objx, objy );
Else
{
F [I]. objid. style. pixelleft = objx;
F [I]. objid. style. pixeltop = objy;
}
}
}
If (document. layers)
{
For (VAR I = 0; I <F. length; I ++)
{
VaR objid = f [I]. objid;
Switch (F [I]. Align)
{
Case alleft: objx = pagexoffset + F [I]. X; break;
Case alcenter: objx = pagexoffset + math. Ceil (window. innerWidth-objId.width)/2) + F [I]. X; break;
Case alright: objx = pagexoffset + window. innerwidth-f [I]. X-document. objid. width; break;
}
Switch (F [I]. valign)
{
Case altop: objy = pageyoffset + F [I]. Y; break;
Case almiddle: objy = pageyoffset + math. Ceil (window. innerheight/2) + F [I]. Y; break;
Case Albottom: objy = pageyoffset + window. innerheight-f [I]. Y-document. objid. height; break;
}
If (T [I]. Smooth) smoothmove (F [I]. objid, objx, objy );
Else
{
Document. objid. Left = objx;
Document. objid. Top = objy;
}
}
}
SetTimeout ("floatmove ();", 50 );
}
Function smoothmove (OBJ, x, y)
{
VaR percent;
If (document. All)
{
Percent =. 1 * (X-obj. style. pixelleft );
If (percent> 0) percent = math. Ceil (percent); else percent = math. Floor (percent );
OBJ. style. pixelleft + = percent;
Percent =. 1 * (Y-obj. style. pixeltop );
If (percent> 0) percent = math. Ceil (percent); else percent = math. Floor (percent );
OBJ. style. pixeltop + = percent;
}
If (document. layers)
{
Percent =. 1 * (X-document. objid. Left );
If (percent> 0) percent = math. Ceil (percent); else percent = math. Floor (percent );
Document. objid. Left + = percent;
Percent =. 1 * (Y-document. objid. Top );
If (percent> 0) percent = math. Ceil (percent); else percent = math. Floor (percent );
Document. objid. Top + = percent;
}
}
SetTimeout ("floatmove ();", 50 );
Call example:
<Script language = "JavaScript" src = "lib/floatdiv. js"> </SCRIPT>
<Script language = "JavaScript">
If (navigator. appname = "Netscape ")
{
Document. write ("<layer id = ad_hr Top = 300 width = 100 Height = 120> <a href = http://www.fpc.org.cn/hr/040522.htm target = _ blank> </a> </layer> ");
}
Else
{
Document. write ("<Div id = ad_hr style = 'position: absolute; width: 120; top: 300; left: 5; visibility: visible; Z-index: 1'> <a href = http://www.fpc.org.cn/hr/040522.htm target = _ blank> </a> </div> ");
}
Adddiv (ad_hr, alright, altop, 0, 30, true );
</SCRIPT>