本文实例讲述了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> <div> </div> <!--div id="floatAd"> <div></div> <div></div> </div> <div id="floatSide"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("<div id="floatAd"+floatAdImg+") no-repeat; width:487px; height:350px; cursor:pointer; display:none; ">"); document.writeln("<div onclick="closeFAd();"></div>"); document.writeln("<div onclick="open_online();"></div>"); document.writeln("</div>"); //浮动侧栏 document.writeln("<div+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);
效果图如下:
希望本文所述对大家JavaScript程序设计有所帮助。