您好,欢迎访问一九零五行业门户网

JS简单实现浮动窗口

这篇文章主要介绍了js简单实现浮动窗口效果,涉及javascript操作浮动窗口的创建、打开、关闭等相关操作技巧,需要的朋友可以参考下
本文实例讲述了js简单实现浮动窗口效果。分享给大家供大家参考,具体如下:
html部分:
<!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> <p style="height:2000px; background:#ccc; display:none;"> </p> <!--p 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;"> <p onclick="closefad();" style=" width:26px; height:26px; float:right;"></p> <p style="width:487px; height:320px; float:right;" onclick="open_online();"></p> </p> <p 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();></p--> </body> </html> <script type="text/javascript" src="online.js"></script>
js部分:
// 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("<p 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("<p onclick=\"closefad();\" style=\" width:26px; height:26px; float:right;\"></p>"); document.writeln("<p style=\"width:487px; height:320px; float:right;\" onclick=\"open_online();\"></p>"); document.writeln("</p>"); //浮动侧栏 document.writeln("<p 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();\"></p>"); //关闭浮动广告 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);
效果图如下:
相关推荐:
js实现动态雪花飘落
canvas与js实现动态时钟动画
以上就是js简单实现浮动窗口的详细内容。
其它类似信息

推荐信息