网页中如何加入悬浮窗口?能一直悬浮在浏览器某个地方的。
2个回答
展开全部
1、首先创建一个名为“topwindows.html”的网页文件,其中的内容将被展示主页浮动窗口中。
2、网页浮动窗口对应的部分代码如下所示:
<html>
<style>
.img_wd{
font-size:30;padding-top:20px;
text-align:left;padding-left:70px;line-height:40px;
background:url(110.jpg) top center no-repeat;
width:252px;height:127px;line-heiht:10px;
text-align:center;
font-family:"微软雅黑,仿宋,楷体,黑体"
color: #fafafa;
text-shadow : rgba(255,255,255,0.5) 0 5px 6px, rgba(255,255,255,0.2) 1px 3px 3px;
}
</style>
<body>
<div class="img_wd" style="">
青春就是这么任性!<Br>
Younger GOOD
</div>
</body>
</html>
3、接着将如图所示的代码添加到主页<Body>和</Body>之间:
其中标签"fdck”中的属性SRC指向浮动窗口的网页地址。
<div id="img" style="position: absolute;visibility :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>
4、接下来需要添加浮动窗口随时运行的行为,对应代码如下:
<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>
5、在此需要说明一点,需要将以上所有代码(包括JS脚本)全部放置在<body>和</body>之间。
6、最后查看一下浮动窗口的效果,会发现浮动窗口在网页中不断的移动,当鼠标悬停其上时会停止移动,点击“隐藏”按钮将自动隐藏悬浮窗口。
2、网页浮动窗口对应的部分代码如下所示:
<html>
<style>
.img_wd{
font-size:30;padding-top:20px;
text-align:left;padding-left:70px;line-height:40px;
background:url(110.jpg) top center no-repeat;
width:252px;height:127px;line-heiht:10px;
text-align:center;
font-family:"微软雅黑,仿宋,楷体,黑体"
color: #fafafa;
text-shadow : rgba(255,255,255,0.5) 0 5px 6px, rgba(255,255,255,0.2) 1px 3px 3px;
}
</style>
<body>
<div class="img_wd" style="">
青春就是这么任性!<Br>
Younger GOOD
</div>
</body>
</html>
3、接着将如图所示的代码添加到主页<Body>和</Body>之间:
其中标签"fdck”中的属性SRC指向浮动窗口的网页地址。
<div id="img" style="position: absolute;visibility :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>
4、接下来需要添加浮动窗口随时运行的行为,对应代码如下:
<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>
5、在此需要说明一点,需要将以上所有代码(包括JS脚本)全部放置在<body>和</body>之间。
6、最后查看一下浮动窗口的效果,会发现浮动窗口在网页中不断的移动,当鼠标悬停其上时会停止移动,点击“隐藏”按钮将自动隐藏悬浮窗口。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询