// define class Popup function Popup(param) { this.popup = param; this.height = this.popup.height(); } Popup.prototype.showPopup = function() { var winHt = $(window).height(); var popupMask = $(''); if($('body .popup-mask').length == 0) { $('body').append(popupMask); } $('.popup-mask').animate({height: winHt+"px"}); this.centerPopup(); this.popup.css('visibility', 'visible'); $('body').css('overflow-y', 'hidden'); //console.info('显示执行成功!!!'); }; Popup.prototype.centerPopup = function() { var winHt = $(window).height(); this.height = this.popup.height(); var marginTop = (winHt - this.height)/2; this.popup.css('top', marginTop + 'px'); }; Popup.prototype.hidePopup = function() { this.popup.css('top', -9999+'px'); $('body').css('overflow-y', 'auto'); $('.popup-mask').animate({height:0},function() { $('.popup-mask').remove(); }); if(this.hideBack) { var callback = this.hideBack; callback(); } //console.info('隐藏执行成功!!!'); }; //初始化popup function initPopup(obj, errorStatus) { //console.info(errorStatus); var ele = obj.popup; var textList = ele.find('input[type=text]'); var selectList = ele.find('select'); ele.data().errorStatus = (errorStatus == undefined)?false:true; ele.data().attr = []; // 遍历文本框移除错误提示信息 textList.each(function() { $(this).removeClass('error-data'); $(this).next('i').removeClass('error-data'); var tmp = { type: 'input', id: $(this).attr('id'), val: $(this).val() }; ele.data().attr.push(tmp); }); // 遍历下拉框 selectList.each(function() { var tmp = { type: 'select', id: $(this).attr('id'), val: $(this).val() }; ele.data().attr.push(tmp); }); // 移除按钮不可点击状态 ele.find('.status-change-btn').removeClass('whyc-btn-disabled'); //console.info(ele.data().errorStatus); // 读取参数失败 if(ele.data().errorStatus) { ele.find('.status-change-btn').addClass('whyc-btn-disabled'); } } var popup = new Popup($('.popup').eq(0)); $('.popup').eq(0).find('.close').bind('click', function() { popup.hidePopup(); // 隐藏弹出框和遮罩层 }); $('[data-toggle="popup"]').click(function() { popup.showPopup(); // 显示弹出框和遮罩层 }); /*$('body').on('click', '.popup-mask', function() { popup.hidePopup(); // 隐藏弹出框和遮罩层 });*/ // 窗口大小改变 $(window).resize(function() { popup.hidePopup(); // 隐藏弹出框和遮罩层 });