JS封装的模仿qq右下角消息弹窗功能示例
程序员文章站
2023-11-13 20:33:04
本文实例讲述了js封装的模仿qq右下角消息弹窗功能。分享给大家供大家参考,具体如下:
在我们的日常开发中,或者生活中,经常需要用到弹出窗。这里我们就用js模拟一下qq消息...
本文实例讲述了js封装的模仿qq右下角消息弹窗功能。分享给大家供大家参考,具体如下:
在我们的日常开发中,或者生活中,经常需要用到弹出窗。这里我们就用js模拟一下qq消息一样的弹出窗。
直接贴代码:
<!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=gbk" /> <title>www.jb51.net javascript实现网页右下角弹出窗口代码</title> </head> <body> <script type="text/javascript"> var showmsg={ title:'提示', content:'模拟qq弹出框消息提醒', width:'300px', height:'100px', settitle:function(value){ this.title=value; }, setcontent:function(value){ this.content=value; }, gettitle:function(){ return this.title; }, getcontent:function(){ return this.content; }, show:function(){ //弹窗div var _winpopdiv = document.createelement('div'); _winpopdiv.id="_winpopdiv"; _winpopdiv.style.csstext = 'width:300px; position:absolute; right:0; bottom:0; border:1px solid #666; margin:0; padding:1px; overflow:hidden; display:block;'; //消息标题div var _titlediv= document.createelement('div'); _titlediv.id="_titlediv"; _titlediv.innerhtml=this.gettitle(); _titlediv.style.csstext = 'width:100%; height:22px; line-height:20px; background:#ffcc00; font-weight:bold; text-align:left; font-size:14px;'; _winpopdiv.appendchild(_titlediv); //关闭消息按钮span var _closespan= document.createelement('span'); _closespan.id="_closespan"; _closespan.innerhtml="x"; _closespan.style.csstext = 'position:absolute; right:4px; top:-1px; color:#fff; cursor:pointer;font-size:14px;'; _titlediv.appendchild(_closespan); //内容div var _condiv= document.createelement('div'); _condiv.id="_condiv"; _condiv.style.csstext = 'width:100%; height:110px; line-height:80px; font-weight:bold; font-size:12px; color:#ff0000; text-decoration:underline; text-align:center;'; _condiv.innerhtml=this.getcontent(); _winpopdiv.appendchild(_condiv); document.body.appendchild(_winpopdiv); //关闭span绑定事件 var closediv = document.getelementbyid("_closespan"); if(closediv.addeventlistener){ closediv.addeventlistener("click",function(e){ if (window.event != undefined) { window.event.cancelbubble = true; } else if (e.stoppropagation) { e.stoppropagation(); } document.getelementbyid('_winpopdiv').style.csstext="display:none;"; },false); }else if(closediv.attachevent){ closediv.attachevent("onclick",function(e){ if (window.event != undefined) { window.event.cancelbubble = true; } else if (e.stoppropagation) { e.stoppropagation(); } document.getelementbyid('_winpopdiv').style.csstext="display:none;"; }); } } }; showmsg.show(); </script> </body> </html>
这里使用在线html/css/javascript代码运行工具:http://tools.jb51.net/code/htmljsrun,测试可得到如下运行效果:
更多关于javascript相关内容感兴趣的读者可查看本站专题:《javascript窗口操作与技巧汇总》、《javascript事件相关操作与技巧大全》、《javascript页面元素操作技巧总结》、《javascript操作dom技巧总结》、《javascript错误与调试技巧总结》、《javascript数据结构与算法技巧总结》及《javascript数学运算用法总结》
希望本文所述对大家javascript程序设计有所帮助。
上一篇: 怎么用会声会影制作重复的镜头?