Copy codeThe Code is as follows:
<! -- Random floating advertisement starts -->
<Div id = "float" style = "position: absolute; z-index: 3; (I suggest you set this to 100 so that the floating chart will not be covered) left: 512px; width: 83px; top: 9px; height: 53px; ">
</div>
<Script type = "text/javascript">
<! -- Random floating advertisement -->
Var xPos = 0, yPos = 0; // x, Y axis
Var xon = 0; // The image moves in the direction of the X axis.
Var yon = 0; // The image moves in the Y axis.
Var step = 1; // The moving distance.
Var img = document. getElementByIdx_x ("float"); // picture layer
Function floatP ()
{
Var width = document. body. clientWidth; // browser width
Var height = document. body. clientHeight; // browser height
Var Hoffset = img. offsetHeight; // Image Height
Var Woffset = img. offsetWidth; // Image Width
Img. style. left = xPos + document. body. scrollLeft; // The picture is located at the left of the browser.
Img. style. top = yPos + document. body. scrollTop; // The picture is located at the top of the browser.
If (yon = 0 ){
YPos = yPos + step; // The picture is moved up and down on the Y axis
} Else {
YPos = yPos-step;
}
If (yPos <0) {// float to the top and move down along the Y axis
Yon = 0;
YPos = 0;
}
If (yPos> = (height-Hoffset) {// float to the lower end and move up along the Y axis
Yon = 1;
YPos = (height-Hoffset );
}
If (xon = 0) {// move the X axis to the right
XPos = xPos + step;
} Else {
XPos = xPos-step; // move the X axis to the left
}
If (xPos <0) {// when it floats to the left side, it moves right along the X axis
Xon = 0;
XPos = 0;
}
If (xPos> = (width-Woffset) {// move along the X axis to the left when drifting to the right
Xon = 1;
XPos = (width-Woffset );
}
SetTimeout ("floatP ()", 30); // scheduled call.
}
Window. onload = floatP ();
</Script>
Copy codeThe Code is as follows:
<Script>
Var x = 50, y = 60 // the initial position of the floating layer, which corresponds to the initial X coordinate and Y coordinate of the layer respectively.
Var xin = true, yin = true // determines whether the X and Y coordinates of the layer are within the control range. If the xin is the real layer, it moves to the right; otherwise, it moves to the left; yin is the real layer that moves down, otherwise it moves up
Var step = 1 // step for layer movement. The larger the value, the faster the movement speed.
Var delay = 10 // interval of layer movement, in milliseconds. The smaller the value, the faster the movement.
Var obj = document. getElementByIdx_x ("float") // capture the layer with the id of ad as the floating target
Function floatAD (){
Var L = T = 0 // The left boundary (L) and upper boundary (T) coordinates of the layer moving range
Var R = document. body. clientWidth-obj.offsetWidth // The right boundary of the layer Movement
Var B = document. body. clientHeight-obj.offsetHeight // bottom boundary of layer Movement
Obj. style. left = x + document. body. scrollLeft // update the X coordinate of the layer to realize the motion on the X axis. document. body. scrollLeft is the distance from the scroll bar in the document area to the right to ensure that the layer is still within the visible range when the scroll bar is right.
Obj. style. top = y + document. body. scrollTop // update the Y coordinate of the layer to realize the motion on the Y axis. document. body. scrollTop is the scroll bar drop-down distance in the document area to ensure that the layer is still within the visible range when the scroll bar is pulled down.
X = x + step * (xin? 1:-1) // determine the motion direction of the layer on the X axis by judging the range of the layer.
If (x <L) {xin = true; x = L} // processing when the layer exceeds the left boundary
If (x> R) {xin = false; x = R} // processing when the layer exceeds the right boundary
Y = y + step * (yin? 1:-1) // determine the motion direction of the layer on the Y axis by judging the range of the layer.
If (y <T) {yin = true; y = T} // processing when the layer exceeds the upper boundary
If (y> B) {yin = false; y = B} // processing when the layer exceeds the bottom boundary
}
Var itl = setInterval ("floatAD ()", delay) // execute the floatAD function once every delay second
Obj. onmouseover = function () {clearInterval (itl)} // clear the preceding interval event when moving the cursor over the layer to stop the motion when moving the mouse over the layer.
Obj. onmouseout = function () {itl = setInterval ("floatAD ()", delay)} // layer starts the interval event when the mouse is removed, achieve the effect of moving layer when the mouse is removed
</Script>
Note:
Insert Flash and floating advertisements into the webpage. You will find the floating advertisements below when they are floating onto the Flash,
How can we solve this problem,
Others are simple
Add the following statement to the position of the flash code.
<Param name = "wmode" value = "opaque">
Example:
If the code for the flash location is as follows:
Copy codeThe Code is as follows:
<Object classid = "clsid: D27CDB6E-AE6D-11cf-96B8-444553540000" codebase = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width = "780" height = "165">
<Param name = "movie" value = "banner1.swf">
<Param name = "quality" value = "high">
<Param name = "menu" value = "false">
<Param name = "wmode" value = "opaque"> <! -- Mainly this sentence -->
<Embed src = "banner1.swf" quality = "high" pluginspage = "http://www.macromedia.com/go/getflashplayer" type = "application/x-shockwave-flash" width = "780" height = "165"> </embed>
</Object>