小編給大家分享一下JS如何模仿qq右下角消息彈窗功能,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
創(chuàng)新互聯(lián)為客戶提供專業(yè)的成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、程序、域名、空間一條龍服務(wù),提供基于WEB的系統(tǒng)開發(fā). 服務(wù)項(xiàng)目涵蓋了網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站程序開發(fā)、WEB系統(tǒng)開發(fā)、微信二次開發(fā)、成都做手機(jī)網(wǎng)站等網(wǎng)站方面業(yè)務(wù)。具體如下:
在我們的日常開發(fā)中,或者生活中,經(jīng)常需要用到彈出窗。這里我們就用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實(shí)現(xiàn)網(wǎng)頁(yè)右下角彈出窗口代碼</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;'; //消息標(biāo)題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); //關(guān)閉消息按鈕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); //內(nèi)容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); //關(guān)閉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代碼運(yùn)行工具:http://tools.jb51.net/code/HtmlJsRun,測(cè)試可得到如下運(yùn)行效果:
以上是“JS如何模仿qq右下角消息彈窗功能”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
當(dāng)前文章:JS如何模仿qq右下角消息彈窗功能-創(chuàng)新互聯(lián)
地址分享:http://chinadenli.net/article6/djjjig.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、虛擬主機(jī)、搜索引擎優(yōu)化、手機(jī)網(wǎng)站建設(shè)、定制開發(fā)、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容