Js + Css的msn式的popup提示窗口的实现

Msn的提示窗口非常经典,所以我们也做一个javascript实现一下,给大家逗乐用。

 

闲话不多说,Javascript代码如下:

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /*eMsg*/
None.gif
var  divTop,divLeft,divWidth,divHeight,docHeight,docWidth,i  =   0 ;
None.gif
var  eMsg  =   new  Object();
None.gifeMsg.lightSrc 
=  '.. / image / message / light.gif';
None.gifeMsg.closeSrc 
=  '.. / image / message / msgclose.gif';
None.gifeMsg.id 
=  'eMsg';
ExpandedBlockStart.gifContractedBlock.gifeMsg.obj 
=   function () dot.gif {return document.getElementById(eMsg.id);} ;
None.gif
ExpandedBlockStart.gifContractedBlock.gifeMsg.onLoad 
=   function () dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
trydot.gif{
InBlock.gif        divTop 
= parseInt(eMsg.obj().style.top,10);
InBlock.gif        divLeft 
= parseInt(eMsg.obj().style.left,10);
InBlock.gif        divHeight 
= parseInt(eMsg.obj().offsetHeight,10);
InBlock.gif        divWidth 
= parseInt(eMsg.obj().offsetWidth,10);
InBlock.gif        docWidth 
= document.body.clientWidth;
InBlock.gif        docHeight 
= document.body.clientHeight;
InBlock.gif        eMsg.obj().style.top 
= parseInt(document.body.scrollTop,10+ docHeight + 10;
InBlock.gif        eMsg.obj().style.left 
= parseInt(document.body.scrollLeft,10+ docWidth - divWidth;
InBlock.gif        eMsg.obj().style.visibility
="visible";
InBlock.gif        eMsg.timer 
= window.setInterval(eMsg.move,1);
ExpandedSubBlockStart.gifContractedSubBlock.gif        hp.skin.onBeforChange 
= function()dot.gif{
InBlock.gif            
if(eMsg.obj())eMsg.obj().parentNode.removeChild(eMsg.obj());
ExpandedSubBlockEnd.gif        }
;
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    
catch(e)dot.gif{}
ExpandedBlockEnd.gif}
;
ExpandedBlockStart.gifContractedBlock.gifeMsg.onResize 
=   function () dot.gif {
InBlock.gif    i
+=1;
InBlock.gif    
if(i>1000) eMsg.close();
ExpandedSubBlockStart.gifContractedSubBlock.gif    
trydot.gif{
InBlock.gif        divHeight 
= parseInt(eMsg.obj().offsetHeight,10);
InBlock.gif        divWidth 
= parseInt(eMsg.obj().offsetWidth,10);
InBlock.gif        docWidth 
= document.body.clientWidth;
InBlock.gif        docHeight 
= document.body.clientHeight;
InBlock.gif        eMsg.obj().style.top 
= docHeight - divHeight + parseInt(document.body.scrollTop,10);
InBlock.gif        eMsg.obj().style.left 
= docWidth - divWidth + parseInt(document.body.scrollLeft,10);
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    
catch(e)dot.gif{}
ExpandedBlockEnd.gif}
;
ExpandedBlockStart.gifContractedBlock.gifeMsg.move 
=   function () dot.gif {
InBlock.gif    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if(parseInt(eMsg.obj().style.top,10<= (docHeight - divHeight + parseInt(document.body.scrollTop,10)))
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            window.clearInterval(eMsg.timer);
InBlock.gif            eMsg.timer 
= window.setInterval(eMsg.onResize,1);
ExpandedSubBlockEnd.gif        }

InBlock.gif        divTop 
= parseInt(eMsg.obj().style.top,10);
InBlock.gif        eMsg.obj().style.top 
= divTop - 1;
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    
catch(e)dot.gif{}
ExpandedBlockEnd.gif}
;
ExpandedBlockStart.gifContractedBlock.gifeMsg.close 
=   function () dot.gif {
InBlock.gif    eMsg.obj().parentNode.removeChild(eMsg.obj());
InBlock.gif    
if(eMsg.timer) window.clearInterval(eMsg.timer);
ExpandedBlockEnd.gif}
;
ExpandedBlockStart.gifContractedBlock.gifeMsg.createInstance 
=   function (titleHtml,bodyHtml) dot.gif {
InBlock.gif    
if(!titleHtml || !bodyHtml)throw '必须为titleHtml指定值,必须为bodyHtml指定值。';
InBlock.gif    
var odiv = document.createElement('DIV');
InBlock.gif    odiv.id 
= eMsg.id;
InBlock.gif    odiv.innerHTML 
= '<div class="eMsgInner">'
InBlock.gif    
+ '<div class="head">'
InBlock.gif        
+ '<div class="headLeft"><img src="space.gif" height="1" width="1"/></div>'
InBlock.gif        
+ '<div class="headMiddle">+ titleHtml + '</div>'
InBlock.gif        
+ '<div class="headRight"><img src="' + eMsg.closeSrc  + '" onclick="eMsg.close()" align="absmiddle"/></div>'
InBlock.gif    
+ '</div>'
InBlock.gif    
+ '<div class="body" oncontextmenu="eMsg.close();return false;" title="右键关闭">'
InBlock.gif        
+ '<div class="light"><IMG src="' + eMsg.lightSrc + '"></div>'
InBlock.gif        
+ '<div class="content">'
InBlock.gif        
+ bodyHtml    
InBlock.gif        
+ '</div>'
InBlock.gif    
+ '</div>'
InBlock.gif    
+ '</div>';
InBlock.gif    document.body.appendChild(odiv);
ExpandedBlockEnd.gif}
;
None.gif
None.gifwindow.onresize 
=  eMsg.onResize;

 

只有javascript代码还是不够的,我们还需要css来定义样式:

ExpandedBlockStart.gif ContractedBlock.gif DIV#eMsg {dot.gif} {
InBlock.gif    background-color
: #c9d3f3;
InBlock.gif    border-left
: #a6b4cf 1px solid;
InBlock.gif    border-right
: #455690 1px solid; 
InBlock.gif    border-top
: #a6b4cf 1px solid;
InBlock.gif    border-bottom
: #455690 1px solid;
InBlock.gif    visibility
: hidden; 
InBlock.gif    width
: 199px; 
InBlock.gif    height
: 97px; 
InBlock.gif    position
: absolute; 
InBlock.gif    z-index
: 99999; 
InBlock.gif    left
: 0px;
ExpandedBlockEnd.gif
}

None.gifDIV#eMsg DIV.eMsgInner
ExpandedBlockStart.gifContractedBlock.gif
{dot.gif} {
InBlock.gif    border-top
: #ffffff 1px solid;
InBlock.gif    border-left
: #ffffff 1px solid;
InBlock.gif    background-color
:#cfdef4;
InBlock.gif    height
:96px;
InBlock.gif    width
:198px;
ExpandedBlockEnd.gif
}

ExpandedBlockStart.gifContractedBlock.gifDIV#eMsgInner DIV.head
{dot.gif} {width:197px}
ExpandedBlockStart.gifContractedBlock.gifDIV.headLeft
{dot.gif} {width:30px;float:left;}
ExpandedBlockStart.gifContractedBlock.gifDIV.headMiddle
{dot.gif} {
InBlock.gif    width
:150px;
InBlock.gif    text-align
:center;
InBlock.gif    float
:left;
InBlock.gif    padding-top
:2px;
InBlock.gif    color
:green;
InBlock.gif    font-weight
:bold 
ExpandedBlockEnd.gif
}

ExpandedBlockStart.gifContractedBlock.gifDIV.headRight
{dot.gif} {width:16;float:left;}
ExpandedBlockStart.gifContractedBlock.gifDIV.headRight IMG
{dot.gif} {
InBlock.gif    width
:13px;
InBlock.gif    height
:13px;
InBlock.gif    border
:0px;
InBlock.gif    cursor
:hand;
InBlock.gif    margin
:2px;
ExpandedBlockEnd.gif
}

ExpandedBlockStart.gifContractedBlock.gifDIV.body
{dot.gif} {
InBlock.gif    height
:82px;
InBlock.gif    clear
:both;
InBlock.gif    border-right
: #b9c9ef 1px solid; 
InBlock.gif    padding
: 13px;  
InBlock.gif    padding-top
: 1px; 
InBlock.gif    border-top
: #728eb8 1px solid;
InBlock.gif    border-left
: #728eb8 1px solid; 
InBlock.gif    color
: #1f336b; 
InBlock.gif    word-break
: break-all;
InBlock.gif    border-bottom
: #b9c9ef 1px solid;
ExpandedBlockEnd.gif
}

ExpandedBlockStart.gifContractedBlock.gifDIV.light
{dot.gif} {text-align:center;padding:5px 20px}
ExpandedBlockStart.gifContractedBlock.gifDIV.content
{dot.gif} {text-align:center;height:65px;padding-top:10px}
None.gif

 

以上是所有的实现代码,我们在使用时还需要做以下两步

1.我们需要在body标签的前面加上加载message的语句

document.write('<sc' + 'ript>' + 'eMsg.createInstance("月牙儿工作室提示","<div align=left>新增加了邮箱登录和地图查询两个模块欢迎您添加使用。</div>");');

document.write('</s')

document.write('cript>');

2.还需要在bodyonload事件中添加eMsg.onLoad();

 

这样就大功告成了,大家可以从我的博客中看到效果的。

有兴趣的朋友可以把它封装成.net控件呀。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值