Js + Css的msn式的popup提示視窗的實現

來源:互聯網
上載者:User
css|js

Msn的提示視窗非常經典,所以我們也做一個javascript實現一下,給大家逗樂用。
 
閑話不多說,Javascript代碼如下:


只有javascript代碼還是不夠的,我們還需要css來定義樣式:

DIV#eMsg{}{
    background-color: #c9d3f3;
    border-left: #a6b4cf 1px solid;
    border-right: #455690 1px solid;
    border-top: #a6b4cf 1px solid;
    border-bottom: #455690 1px solid;
    visibility: hidden;
    width: 199px;
    height: 97px;
    position: absolute;
    z-index: 99999;
    left: 0px;
}
DIV#eMsg DIV.eMsgInner
{}{
    border-top: #ffffff 1px solid;
    border-left: #ffffff 1px solid;
    background-color:#cfdef4;
    height:96px;
    width:198px;
}
DIV#eMsgInner DIV.head{}{width:197px}
DIV.headLeft{}{width:30px;float:left;}
DIV.headMiddle{}{
    width:150px;
    text-align:center;
    float:left;
    padding-top:2px;
    color:green;
    font-weight:bold
}
DIV.headRight{}{width:16;float:left;}
DIV.headRight IMG{}{
    width:13px;
    height:13px;
    border:0px;
    cursor:hand;
    margin:2px;
}
DIV.body{}{
    height:82px;
    clear:both;
    border-right: #b9c9ef 1px solid;
    padding: 13px; 
    padding-top: 1px;
    border-top: #728eb8 1px solid;
    border-left: #728eb8 1px solid;
    color: #1f336b;
    word-break: break-all;
    border-bottom: #b9c9ef 1px solid;
}
DIV.light{}{text-align:center;padding:5px 20px}
DIV.content{}{text-align:center;height:65px;padding-top:10px}


以上是所有的實現代碼,我們在使用時還需要做以下兩步
1.我們需要在body標籤的前面加上載入message的語句
document.write('<sc' + 'ript>' + 'eMsg.createInstance("月牙兒工作室提示","<div align=left>新增加了郵箱登入和地圖查詢兩個模組歡迎您添加使用。</div>");');
document.write('</s')
document.write('cript>');
2.還需要在body的onload事件中添加eMsg.onLoad();
 
這樣就大功告成了,大家可以從我的部落格中看到效果的。

有興趣的朋友可以把它封裝成.net控制項呀。

/**//*eMsg*/
var divTop,divLeft,divWidth,divHeight,docHeight,docWidth,i = 0;
var eMsg = new Object();
eMsg.lightSrc = '../image/message/light.gif';
eMsg.closeSrc = '../image/message/msgclose.gif';
eMsg.id = 'eMsg';
eMsg.obj = function(){return document.getElementById(eMsg.id);};

eMsg.onLoad = function(){
    try{
        divTop = parseInt(eMsg.obj().style.top,10);
        divLeft = parseInt(eMsg.obj().style.left,10);
        divHeight = parseInt(eMsg.obj().offsetHeight,10);
        divWidth = parseInt(eMsg.obj().offsetWidth,10);
        docWidth = document.body.clientWidth;
        docHeight = document.body.clientHeight;
        eMsg.obj().style.top = parseInt(document.body.scrollTop,10) + docHeight + 10;
        eMsg.obj().style.left = parseInt(document.body.scrollLeft,10) + docWidth - divWidth;
        eMsg.obj().style.visibility="visible";
        eMsg.timer = window.setInterval(eMsg.move,1);
        hp.skin.onBeforChange = function(){
            if(eMsg.obj())eMsg.obj().parentNode.removeChild(eMsg.obj());
        };
    }
    catch(e){}
};
eMsg.onResize = function(){
    i+=1;
    if(i>1000) eMsg.close();
    try{
        divHeight = parseInt(eMsg.obj().offsetHeight,10);
        divWidth = parseInt(eMsg.obj().offsetWidth,10);
        docWidth = document.body.clientWidth;
        docHeight = document.body.clientHeight;
        eMsg.obj().style.top = docHeight - divHeight + parseInt(document.body.scrollTop,10);
        eMsg.obj().style.left = docWidth - divWidth + parseInt(document.body.scrollLeft,10);
    }
    catch(e){}
};
eMsg.move = function(){
    try
    {
        if(parseInt(eMsg.obj().style.top,10) <= (docHeight - divHeight + parseInt(document.body.scrollTop,10)))
        {
            window.clearInterval(eMsg.timer);
            eMsg.timer = window.setInterval(eMsg.onResize,1);
        }
        divTop = parseInt(eMsg.obj().style.top,10);
        eMsg.obj().style.top = divTop - 1;
    }
    catch(e){}
};
eMsg.close = function(){
    eMsg.obj().parentNode.removeChild(eMsg.obj());
    if(eMsg.timer) window.clearInterval(eMsg.timer);
};
eMsg.createInstance = function(titleHtml,bodyHtml){
    if(!titleHtml || !bodyHtml)throw '必須為titleHtml指定值,必須為bodyHtml指定值。';
    var odiv = document.createElement('DIV');
    odiv.id = eMsg.id;
    odiv.innerHTML = '<div class="eMsgInner">'
    + '<div class="head">'
        + '<div class="headLeft"><img src="space.gif" height="1" width="1"/></div>'
        + '<div class="headMiddle">' + titleHtml + '</div>'
        + '<div class="headRight"><img src="' + eMsg.closeSrc  + '" align="absmiddle"/></div>'
    + '</div>'
    + '<div class="body" oncontextmenu="eMsg.close();return false;" title="右鍵關閉">'
        + '<div class="light"><IMG src="' + eMsg.lightSrc + '"></div>'
        + '<div class="content">'
        + bodyHtml   
        + '</div>'
    + '</div>'
    + '</div>';
    document.body.appendChild(odiv);
};

window.onresize = eMsg.onResize;



相關文章

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。