/** * created by xhgx on 2017/4/24. * zhge yilai nnnn xian */ /*本页面依赖于public-method.js*/ /*弹框的基本对象*/ function layer(options){ this.config = { layerboxclass :"layerbox", layerclass:"", width:1115, height:680, zindex:999999999, alerttit:"信息", setoverflow:"overflow-y:scroll", callback: function () { } } $.extend(this.config,options); } layer.prototype = { /*创建弹出框*/ _createdialog:function(state){ var that = this; var str = ""; that.config.zindex++; var s = udp.public.view(); str = '

'+this.config.alerttit+'

'; $("body").append(str); $("body").addclass("no-scroll"); $(".close_btn").click(function (){ that.deldialog($(this)); $("body").removeclass() ; }); $("."+that.config.layerboxclass).eq($(".overlay").size()-1).css({left: (s.w- this.config.width)/2+"px",top: (s.h-this.config.height)/2+"px"}); if(that.config.callback){ that.config.callback.apply(this,[]); } return str; }, /*移除弹框*/ deldialog:function(ele){ $(ele).parents(".overlay").remove(); }, /*移动弹框*/ movedialog:function(ele){ var that = this; var s = udp.public.view(); $(".layerheader").mousedown(function(e){ var theme = this; var moveele = $(theme).parents("."+that.config.layerboxclass); e.stoppropagation(); e.preventdefault(); var x = e.clientx - moveele.offset().left; var y = e.clienty - moveele.offset().top; $(document).mousemove(function(e){ var lf = e.clientx-x; var tp = e.clienty-y; lf=lf<0 ? 0:lf; lf=lf>(s.w - moveele.width()) ? (s.w - moveele.width()):lf; tp=tp<0 ? 0:tp; tp=tp>(s.h - moveele.height()) ? (s.h - moveele.height()):tp; moveele.css({left: lf+"px",top:tp+"px"}); }); $(document).mouseup(function(){ $(this).unbind("mousemove"); }); }); }, /*手动调整弹框大小*/ revampsize:function(){ var that = this; var s = udp.public.view(); $(".layer-size").mousedown(function(e){ var theme = this; var moveele = $(theme).parents("."+that.config.layerboxclass); var x = e.clientx - moveele.width(); var y = e.clienty - moveele.height(); $(document).mousemove(function(e){ var width = e.clientx-x+"px"; var height = e.clienty-y+"px"; width=width<0 ? 0:width; width=width>s.w ? s.w :width; height=height<0 ? 0:height; height=height>s.h ? s.h :height; moveele.css({width:width,height:height}); }); $(document).mouseup(function(){ $(document).unbind("mousemove"); }); }); } ,show:function(){ this._createdialog(); this.movedialog(); this.revampsize(); } } ;(function(win){ if(win["udp"]){ win["udp"].layer = layer; }else{ win.udp = {layer:layer}; } })(window); var layer = new layer({ layerclass:"layercontianer2",//存放页面的容器类名 width:1115, height:685, alerttit:"", setoverflow:"overflow-y:none",//设置滚动的属性 overflow-y:设置竖向 overflow-x:设置横向 callback:function(){ $(".inp_btn").click(function(){ layer.show(); }); } }); $(".j_headlogin").click(function(){ layer.show(); });