jquery 人性化的提示框 showMsg

 jQuery.fn.showMsg=function(json)
{    
    if(json==null)
        json={};
    var bodyScrollSize=this.getBodyScrollSize();
    var bodySize=this.getBodySize();
    var left=bodyScrollSize.left;
    var top=bodyScrollSize.top;
    if(json.autoMiddle!=true)
    {
        if(json.left)left=left+json.left;
        if(json.top)top=top+json.top;
    }
    else if(json.autoMiddle==true)
    {
        var _w=this.width();
        var _h=this.height();
        top=(bodySize.height-_h)/2 + top;
        left=(bodySize.width-_w)/2;
    }
    if(top+this.height()>bodyScrollSize.height)
        bodyScrollSize.height=top+this.height();
    if(left+this.width()>bodyScrollSize.width)
        bodyScrollSize.width=left+this.width();
    
    if(json.coverBody==true)
    {
        $("<iframe id='jq_effect_backGroundIframe' style='z-index:1;filter:mask();overflow:hidden;border:0px;margin:0; padding:0;position:absolute;width:"+bodyScrollSize.width+"px;height:"+bodyScrollSize.height+"px;top:0px;left:0px' scrolling='auto' frameborder='0' ></iframe>").appendTo("body");
        var jqCover=$("<div id='jq_effect_backGroundDiv'></div>");
        var _css = { "background-color":json.color==undefined?"#000":json.color, "position":"absolute","overflow":"hidden", "-moz-opacity": "0.75" , "filter":"alpha(opacity=75)","z-index":"2" ,"opacity":"0.75", "top" : "0px" , "left":"0px","width":bodyScrollSize.width,"height":bodyScrollSize.height };         
        jqCover.css(_css);
        jqCover.appendTo("body");
    }
    if(typeof(json.msg)!="undefined")
        this.html(json.msg);
    this.css("height","auto");
    this.css("position","absolute").css("z-index","100");
    this.css("left",left+"px").css("top",top+"px").fadeIn("slow");
    if(jQuery.msgShowObj!=undefined)
    {
        try{jQuery.msgShowObj.fadeOut('slow');}catch(e){};
    }
    jQuery.msgShowObj=this;
    if(typeof(json.callback)!="undefined")
        jQuery.msgCallBack=json.callback;
    else
        jQuery.msgCallBack=null;
    jQuery.cc=undefined;
    if(json.autoClose!=false)
    {
        jQuery.cc=window.setTimeout("try{jQuery.msgShowObj.closeMsg();}catch(e){}",json.time==undefined?2000:json.time);
    }
    return this;
}
jQuery.fn.closeMsg=function()
{
    this.fadeOut('slow',jQuery.msgCallBack);
    jQuery.msgShowObj=undefined;
    $('#jq_effect_backGroundIframe').remove();
    $('#jq_effect_backGroundDiv').remove();
    
    return this;
}

jQuery.fn.getBodyScrollSize=function()
{
    var bodySL, bodyST, bodySW, bodySH;
    if(window.pageXOffset)
    {
        bodySL=window.pageXOffset;
        bodySW=window.innerWidth;
        bodyST=window.pageYOffset;
        bodySH=window.innerHeight;
    }
    else if(document.documentElement)
    {    
        bodySL=document.documentElement.scrollLeft;
        bodySW=document.documentElement.scrollWidth; //-10
        bodyST=document.documentElement.scrollTop;
        bodySH=document.documentElement.clientHeight>document.documentElement.scrollHeight?document.documentElement.clientHeight:document.documentElement.scrollHeight;
    }
    else if(document.body)
    {
        bodySL=document.body.scrollLeft;
        bodySW=document.body.scrollWidth;
        bodyST=document.body.scrollTop;
        bodySH=document.body.clientHeight>document.body.scrollHeight?document.body.clientHeight:document.body.scrollHeight;
    }

    return {"top":bodyST,"left":bodySL,"width":bodySW,"height":bodySH};
}

jQuery.fn.getBodySize=function()
{
    var bodyCW, bodyCH;
    if(window.innerWidth)
        bodyCW=window.innerWidth;
    else if(document.documentElement&&document.documentElement.clientWidth)
        bodyCW=document.documentElement.clientWidth;
    else if(document.body)
        bodyCW=document.body.clientWidth; //author: meizz

    if(window.innerHeight)
        bodyCH=window.innerHeight;
    else if(document.documentElement&&document.documentElement.clientHeight)
        bodyCH=document.documentElement.clientHeight;
    else if(document.body)
        bodyCH=document.body.clientHeight;
    
    return {"width":bodyCW,"height":bodyCH};
}

function _alert()
{
    alert("OK");
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值