遮罩

来源:互联网 发布:edius4.7软件下载 编辑:程序博客网 时间:2024/05/16 07:02
/**
*WindowMask 遮罩 开始
*使用:var mask=new WindowMask(); mask.show();
**/
function WindowMask(id){
 if(id){
  this.id=id;
  this.jqueryId="#"+id
 }else{
  this.id="windowMask"
  this.jqueryId="#windowMask"
 }
 this.style={
  "position":"absolute",
  "top":"0px",
  "left":"0px",
  "width":"100%",
  "background-color":"#333333",
  "opacity":" 0.5",
  "filter":"alpha(opacity=50)",
  "z-index":"99",
  "height":"0px"
 }
}
WindowMask.fn=WindowMask.prototype;
WindowMask.fn.init=function(){ //初始化
 var style="";
 if($(window).height()>$(document).height())
 {
     this.style.height=($(window).height()-5)+"px";
 }else{
     this.style.height=$(document).height()+"px";
 }
 for(var key in this.style)
 {
  style+=key+":"+this.style[key]+";";
 }
 $("body").append("<div id=\""+this.id+"\" style=\""+style+"\" ></div>");
 $(window).resize(jQuery.proxy(this.resize,this));
}
WindowMask.fn.setStyle=function(cssJson){ //设置样式
 $(this.jqueryId).css(cssJson);
}
WindowMask.fn.setText=function(msg){ //设置文本
 var msgDIV="<div style=\"margin-top:"+$(window).height()*0.45+"px; width:100%;text-align:center;color:#ffffff;font-weight:bold;\">"+msg+"</div>"
 $(this.jqueryId).html(msgDIV);
}
WindowMask.fn.setHTML=function(html){  //设置html
  $(this.jqueryId).html(msg);
}
WindowMask.fn.show=function(msg){  //显示
 if($(this.jqueryId).length==0){
  this.init();
  }
 if(msg) this.setText(msg);
 this.setStyle({"display":"block"});
}
WindowMask.fn.hide=function(){
 this.setStyle({"display":"none"});
}
WindowMask.fn.resize=function(){ //遮罩随窗口改变
    if($(window).height()>$(document).height())
 {
     this.style.height=($(window).height()-5)+"px";
 }else{
     this.style.height=$(document).height()+"px";
 }
 this.setStyle({"height":this.style.height});
}
/**WindowMask 遮罩   结束**/
原创粉丝点击