怎么在网页中添加浮动窗口
1、首先我们创建一个名为“topwindows.html”的网页文件,其中的内容将被展示主页浮动窗口中。

4、<div id="img" style="position: absolute;visibil足毂忍珩ity :hidden;padding:0px;" onmouseover="clearInterval(interval)" onmouseout="interval = setInterval('changePos()', delay)" align="middle"><span style="CURSOR:hand;color:red;font-weight:bold;font-align:center;font-size:12px;padding-left:0px;" onclick="clearInterval(interval);fdck.style.visibility = 'hidden';img.style.visibility = 'hidden';">隐藏</span><div id="fdck" style="width:100%; height:100%; font-align:center; visibility:visible;border:0px; background-color: no"><iframe width=320 height=150 src="topWindows.html" frameborder=no scrolling="no"></iframe></div></div>
5、接下来我们需要添加浮动窗口随时运行的行为,在踊辽嚏囱此小编利用JS脚本语言来实现。对应代码如下:<script language=javascript>var xPos = 20;var yPos = document.body.clientHeight;var step = 1;var delay = 30;var height = 0;var Hoffset = 0;var Woffset = 0;var yon = 0;var xon = 0;var pause = true;var interval;img.style.top = yPos;function changePos() {width = document.body.clientWidth;height = document.body.clientHeight;Hoffset = img.offsetHeight;Woffset = img.offsetWidth;img.style.left = xPos + document.body.scrollLeft;img.style.top = yPos + document.body.scrollTop;if (yon) {yPos = yPos + step;}else {yPos = yPos - step;}if (yPos < 0) {yon = 1;yPos = 0;}if (yPos >= (height - Hoffset)) {yon = 0;yPos = (height - Hoffset);}if (xon) {xPos = xPos + step;}else {xPos = xPos - step;}if (xPos < 0) {xon = 1;xPos = 0;}if (xPos >= (width - Woffset)) {xon = 0;xPos = (width - Woffset);}}function start() {img.style.visibility = "visible";interval = setInterval('changePos()', delay);}start();</script>

7、最后查看一下浮动窗口的效果,会发现浮动窗口在网页中不断的移动,当鼠标悬停其上时会停止移动,点击“隐藏”按钮将自动隐藏悬浮窗口。
