ITPub博客

首页 > Linux操作系统 > Linux操作系统 > QQ弹出窗口的JavaScript代码

QQ弹出窗口的JavaScript代码

原创 Linux操作系统 作者:李飞java 时间:2009-09-17 14:36:42 0 删除 编辑

Html代码和JavaScript代码来模仿一下QQ、MSN、淘宝旺旺、等等的聊天软件这一功能。
先给大家贴出来的是Html代码:


类似于QQ弹出窗口的JavaScript代码示例


var MSG1 = new CLASS_MSN_MESSAGE(200,120,"短消息提示:","您有1封消息","点击查看","test.html",1);
MSG1.rect(null,null,null,screen.height-50);
MSG1.speed = 10;
MSG1.step = 5;
MSG1.show();




以下是popmsg.js代码:
function CLASS_MSN_MESSAGE(width,height,caption,title,message,href,id){
    this.title = title;
    this.caption= caption;
    this.message= message;
this.href= href;
this.id= id;
    this.width    = width?width:200;
    this.height = height?height:120;
    this.timeout= 150;
    this.speed    = 20;
    this.step    = 1;
    this.right    = screen.width -1;
    this.bottom = screen.height;
    this.left    = this.right - this.width;
    this.top    = this.bottom - this.height;
    this.timer    = 0;
    this.pause    = false;
    this.close    = false;
    this.autoHide    = true;
}
CLASS_MSN_MESSAGE.prototype.hide = function(){
    if(this.onunload()){
        var ffset = this.height>this.bottom-this.top?this.height:this.bottom-this.top;
        var me = this;
        if(this.timer>0){  
            window.clearInterval(me.timer);
        }
        var fun = function(){
            if(me.pause==false||me.close){
                var x = me.left;
                var y = 0;
                var width = me.width;
                var height = 0;
                if(me.offset>0){
                    height = me.offset;
                }
                y = me.bottom - height;
                if(y>=me.bottom){
                    window.clearInterval(me.timer);
                    me.Pop.hide();
                } else {
                    me.offset = me.offset - me.step;
                }
                me.Pop.show(x,y,width,height);   
            }            
        }
        this.timer = window.setInterval(fun,this.speed)     
    }
}
CLASS_MSN_MESSAGE.prototype.onunload = function() {
    return true;
}
CLASS_MSN_MESSAGE.prototype.oncommand = function(){
    this.hide();
}
CLASS_MSN_MESSAGE.prototype.show = function(){
    var Popup = window.createPopup(); //IE5.5+
    this.Pop = oPopup;
    var w = this.width;
    var h = this.height;
    var str = "

"
        str += ""
        str += ""
        str += ""
        str += ""
        str += ""
        str += ""
        str += ""
        str += ""
        str += ""
        str += "
" + this.caption + ""
        str += "×
"
        str += "
" + this.title + "

"
        str += ""
        str += "
"
        str += "
"
        str += "
"
    oPopup.document.body.innerHTML = str;
    this.offset = 0;
    var me = this;
    oPopup.document.body.onmouseover = function(){me.pause=true;}
    oPopup.document.body.onmouseout = function(){me.pause=false;}
    var fun = function(){
        var x = me.left;
        var y = 0;
        var width    = me.width;
        var height    = me.height;
            if(me.offset>me.height){
                height = me.height;
            } else {
                height = me.offset;
            }
        y = me.bottom - me.offset;
        if(y<=me.top){
            me.timeout--;
            if(me.timeout==0){
                window.clearInterval(me.timer);
                if(me.autoHide){
                    me.hide();
                }
            }
        } else {
            me.offset = me.offset + me.step;
        }
        me.Pop.show(x,y,width,height);   
    }
    this.timer = window.setInterval(fun,this.speed)     
    var btClose = oPopup.document.getElementById("btSysClose");
    btClose.onclick = function(){
        me.close = true;
        me.hide();
    }
    var btCommand = oPopup.document.getElementById("btCommand");
    btCommand.onclick = function(){
        me.oncommand();
   window.open(btCommand.href);
    }   
}
CLASS_MSN_MESSAGE.prototype.speed = function(s){
    var t = 20;
    try {
        t = praseInt(s);
    } catch(e){}
    this.speed = t;
}
CLASS_MSN_MESSAGE.prototype.step = function(s){
    var t = 1;
    try {
        t = praseInt(s);
    } catch(e){}
    this.step = t;
}
CLASS_MSN_MESSAGE.prototype.rect = function(left,right,top,bottom){
    try {
        this.left        = left    !=null?left:this.right-this.width;
        this.right        = right    !=null?right:this.left +this.width;
        this.bottom        = bottom!=null?(bottom>screen.height?screen.height:bottom):screen.height;
        this.top        = top    !=null?top:this.bottom - this.height;
    } catch(e){}
}

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22434610/viewspace-614900/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 网址大收藏
请登录后发表评论 登录
全部评论

注册时间:2009-09-02

  • 博文量
    42
  • 访问量
    56969