复制代码 代码如下: /************************************自动适应的图片弹窗*********************************/ var autoImg=function(argcs){/*调整图片大小,等比例缩放argcs["maxHeight"]=>最大高度,argcs["maxWidth"]=>最大宽度,argcs["height"]=>图片高度,argcs["width"]=>图片宽度*/ var _maxHeight=""; var _maxWidth=""; var _newSize=[];
/*********************本类内部变量********************/ var _this=this; var _baseZindex=10000; var _domWidth=$(document).width(); var _domHeight=$(document).height(); /********************本类内部变量*******************/
/********************本类私有函数**********************/ var _getZindex=function(){/*获得z-index->首先遍历网页div元素ID中含有popBox的DOM,获得数量,然后本弹窗背景z-index=基数+当前数量+1,弹框z-index=基数+当前数量+2*/ var _len=$("body").children("div").length; var _countDiv=0; var _divObj=$("body").children("div"); var _reg=/^popBox_/;//正则表达式 for(var i=0;i<_len;i++){ if(_reg.test(_divObj.eq(i).attr("ID"))){ _countDiv+=1; } } return _countDiv;//返回已有弹框的数量 } var _getWinZindex=function(){//获得弹窗的z-index var _winZindex=_baseZindex+_getZindex()+2; return _winZindex; } var _geWinBgZindex=function(){//获得弹窗背景的z-index var _winBgZindex=_baseZindex+_getZindex()+1; return _winBgZindex; } var _renderBg=function(){//渲染背景 www.jb51.net var _winBgZindex=_geWinBgZindex(); //alert($(document).height()); $("body").append("<div id=""+_this.ID+"_bg"></div>");//在body中插入一个半透明的背景 $("#"+_this.ID+"_bg").addClass("popBox_bg").css({height:_domHeight,width:_domWidth,opcity:0}).css("z-index",_winBgZindex).fadeTo(_times,0.7); } var _creatWin=function(){//创建窗体 $("body").append("<div id=""+_this.ID+""></div>"); _renderContent(_content);//渲染弹窗主体 _initWin();//初始化窗体 } var _initWin=function(){//初始化窗体 var _winZindex=_getWinZindex(); var _transHeight=0; if(_height=="auto"){ _transHeight="auto"; }else{ _transHeight=parseInt(_height)+"px"; } $("#"+_this.ID).css({width:parseInt(_width)+"px",height:_transHeight,position:"absolute",opticity:1.0,background:_bgColor}).css("z-index",_winZindex); if(_lock==false){ if(_moveHandle!==undefined&&_moveHandle!==false&&_moveHandle!==" "){ $("#"+_this.ID).children(_moveHandle).css("cursor","move"); //alert(_moveHandle); //alert($("#"+_this.ID).children(_moveHandle).html()); } } _locationWin();//为窗体定位 } var _locationWin=function(){/*为窗体定位topLeft,topCenter,topRight,centerLeft,center,centerRight,bottomLeft,bottomCenter,bottomRight*/ var _windowHeight=parseInt($(window).height()); var _windowWidth=parseInt($(window).width()); //alert(_windowWidth+_height); var _left=(_windowWidth-parseInt(_width))/2; var _top=parseInt($(document).scrollTop())+parseInt(($(window).height()-$("#"+_this.ID).height())/2); $("#"+_this.ID).css({top:_top+"px",left:_left+"px"}); } var _renderContent=function(content){//渲染弹窗主体 $("#"+_this.ID).append(content); } var bindEvent=function(){//绑定事件 if(_this.status!=="kill"&&_this.status!=="init"){ if(_closeButton!==undefined&&_closeButton!==" "&&_closeButton!==false){ $("#"+_this.ID+" "+_closeButton).css("cursor","pointer").live("click",function(e){ _this.unDisplay(); }); }//若设置了关闭(close)按钮 if(_killButton!==undefined&&_killButton!==" "&&_killButton!==false){ $("#"+_this.ID+" "+_killButton).css("cursor","pointer").live("click",function(e){ _this.kill(); }); }//若设置了杀死(kill)按钮 } if(_lock==false){ $("#"+_this.ID).draggable({cancel:""}); } } /*********************本类私有函数*****************/