javascript怎么实现浮动窗口


本文摘自PHP中文网,作者藏色散人,侵删。

javascript实现浮动窗口的方法:首先创建HTML文件;然后通过“function showFAd(){...}”方法打开浮动广告;最后通过“function showFloat(){...}”方法实现打开浮动窗口即可。

本文操作环境:windows7系统、javascript1.8.5版、Dell G3电脑。

javascript怎么实现浮动窗口

具体如下:

HTML部分:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>无标题文档</title>

<style type="text/css">

*{ margin:0; padding:0;}

a img{ border:0;}

</style>

</head>

<body>

<div style="height:2000px; background:#ccc; display:none;">

</div>

<!--div id="floatAd" style=" position:fixed !important; position:absolute; _top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight)); z-index: 2147483647; left: 50%; margin-left: -240px !important; top: 50%; margin-top: -210px !important; background:url(images/onlineSay.jpg) no-repeat; width:487px; height:350px; cursor:pointer;">

<div onclick="closeFAd();" style=" width:26px; height:26px; float:right;"></div>

<div style="width:487px; height:320px; float:right;" onclick="open_online();"></div>

</div>

<div id="floatSide" style=" width:141px; height:579px; position:fixed !important; position:absolute; _top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight)); z-index: 99999; right:0; top:6%; background:url(images/onlineTel.gif);cursor:pointer;" onclick="open_online();></div-->

</body>

</html>

<script type="text/javascript" src="online.js"></script>

JS部分:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

// JavaScript Document

//浮动广告图片

var floatAdImg = "images/onlineSay.jpg";

//浮动侧栏图片

var floatSideImg = "images/onlineTel.gif";

//打开在线沟通

function open_online()

{

 window.open('http://p.qiao.baidu.com//im/index?siteid=7342332&ucid=7601325');

}

//浮动广告

document.writeln("<div id=\"floatAd\" style=\" position:fixed !important; position:absolute; _top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight)); z-index: 2147483647; left: 50%; margin-left: -240px !important; top: 50%; margin-top: -210px !important; background:url("+floatAdImg+") no-repeat; width:487px; height:350px; cursor:pointer; display:none; \">");

document.writeln("<div onclick=\"closeFAd();\" style=\" width:26px; height:26px; float:right;\"></div>");

document.writeln("<div style=\"width:487px; height:320px; float:right;\" onclick=\"open_online();\"></div>");

document.writeln("</div>");

//浮动侧栏

document.writeln("<div style=\" width:141px; height:579px; position:fixed !important; position:absolute; _top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight)); z-index: 99999; right:0; top:6%; background:url("+floatSideImg+");cursor:pointer;\" onclick=\"open_online();\"></div>");

//关闭浮动广告

function closeFAd()

{

 document.getElementById('floatAd').style.display = 'none';

}

//打开浮动广告

function showFAd()

{

 document.getElementById('floatAd').style.display = 'block';

}

//打开浮动窗口

function showFloat()

{

 document.getElementById('floatAd').style.display = 'block';

}

//打开窗口 20 秒仅执行一次

setTimeout(showFAd,20000);

//每个 30 秒执行一次

setInterval(showFloat,30000);

效果图如下:

9d65bfbfce69d79b110d90bbacb7509.png

【相关推荐:javascript高级教程

以上就是javascript怎么实现浮动窗口的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

javascript如何设置字体大小

javascript如何修改div内容

javascript如何实现二叉树的创建和遍历?(代码示例)

javascript中this用法有哪些

javascript中generator函数的详理解

javascript的$是啥

js (javascript)加密算法库 crypto-js 简介

初探埋点系统

20+道必知必会的vue面试题(附答案解析)

javascript中sort()方法怎么用

更多相关阅读请进入《javascript》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...