JS:

window.pop = {
/*alert提示框
*@param title 提示的标题
*@param desc 提示的描述
*@param btnNum 按钮的数量,假如为1,则无视e2,t2,l2参数
*@param e1 第一个按钮的类型,0为关闭类型,1为链接类型
*@param t1 第一个按钮的显示文字
*@param l1 第一个按钮的链接,如果该按钮为关闭类型,此处填0,链接类型填写该按钮链接
*@param e2 第二个按钮的类型,0为关闭类型,1为链接类型
*@param t2 第二个按钮的显示文字
*@param l2 第二个按钮的链接,如果该按钮为关闭类型,此处填0,链接类型填写该按钮链接
*/
alert: function(title, desc, btnNum, e1, t1, l1, e2, t2, l2) {

/*initialize main dom*/
var _body = $('body');
var popShadow = $('<div class="shadow"></div>');
var popWrap = $('<div class="pop-wrap"></div>');
var popContent = $('<div class="pop-content"></div>')
.html('<p class="pop-title">' + title + '</p><p class="pop-describe">' + desc + '</p>')
.appendTo(popWrap);

var popButtonBox = $('<div class="pop-button-box"></div>');
var typeClass = (btnNum == 1) ? 'pop-button-single' : 'pop-button-double'

var btnNum = parseInt(btnNum);//get button's number
var buttonData = [[e1, t1, l1], [e2, t2, l2]];//save data to array

/*loop append buttons to pop-button-box*/
for (var i = 0; i < btnNum; i++) {
if(parseInt(buttonData[i][0]) == 0){
popButtonBox.append(closeDom(buttonData[i][1]));
}else{
popButtonBox.append(linkDom(buttonData[i][1], buttonData[i][2]));
}
};

/*create the close type dom
*@return dom
*/
function closeDom (text) {
return $('<span class="pop-button pop-button-close ' + typeClass + '">' + text + '</span>').bind('click', closeFun);
}

/*create the link type dom
*@return dom
*/
function linkDom (text, link) {
return $('<a class="pop-button pop-button-close ' + typeClass + '" href="' + link + '">' + text + '</a>');
}

/*close pop function*/
function closeFun () {
popShadow.remove();
popWrap.remove();
}

/*append pop to document*/
popShadow.appendTo(_body).fadeIn('fast');
popWrap.append(popButtonBox).appendTo(_body).fadeIn('fast');
popOffset(popWrap);
},

/*确认提示
*@param title 确认提示标题
*@param desc 确认提示描述
*@param fn 确认后回调函数
*/
confirm: function(title, desc, fn) {

var _body = $('body');
var popShadow = $('<div class="shadow"></div>');
var popWrap = $('<div class="pop-wrap"></div>');
var popContent = $('<div class="pop-content"></div>')
.html('<p class="pop-title">' + title + '</p><p class="pop-describe">' + desc + '</p>')
.appendTo(popWrap);

var popButtonBox = $('<div class="pop-button-box"></div>');

var closeBtnDom = $('<span class="pop-button pop-button-close pop-button-double">取消</span>')
.on('click', function(){
popShadow.remove();
popWrap.remove();
})
.appendTo(popButtonBox);

var isFn = typeof fn === 'function';
if (isFn) {
var fnBtnDom = $('<span class="pop-button pop-button-close pop-button-double">确定</span>')
.on('click', fn)
.on('click', function(){
popShadow.remove();
popWrap.remove();
})
.appendTo(popButtonBox);
};

popButtonBox.appendTo(popWrap);

/*append pop to document*/
popShadow.appendTo(_body).fadeIn('fast');
popWrap.appendTo(_body).fadeIn('fast');
popOffset(popWrap);
},

/*错误信息提示
*@param text 错误信息文本
*@param sec 错误信息显示时间,单位毫秒,选填,不填则默认3秒
*/
error: function (text, sec, fn) {
var _body = $('body');
var popError = $('<div class="pop-wrap-error">' + text + '</div>');
$('.pop-wrap-error').remove();
popError.appendTo(_body).fadeIn('fast');
popOffsetX(popError);
sec = sec ? sec : 3000;
setTimeout(function() {
popError.fadeOut('fast',function() {
popError.remove();
});
if (typeof fn == 'function') fn()
},sec);
},

/*loading信息提示
*@param text 读取中提示信息
*/
loading: function (text) {
var _body = $('body');
var popLoading = $('<div class="pop-loading"></div>');
var popContent = $('<p>' + text + '</p>');
var popLoadingEffect = $('<div class="pop-loading-effect"><i class="bounce1"></i><i class="bounce2"></i><i class="bounce3"></i><i class="bounce4"></i><i class="bounce5"></i><i class="bounce6"></i></div>');

popLoading.append(popContent).append(popLoadingEffect).appendTo(_body).fadeIn('fast');
popOffset(popLoading);
},

/*tips信息提示
*@param text 提示信息,强调部分请用strong标签包裹
*/
tips: function () {
var _body = $('body');
var allTips = $('.icon-question-circle');//选取页面中所有问号图标
allTips.each(function(index, el) {//遍历所有问号图标
var _this = $(this);
var text = _this.data('pop-tips');//获取当前tip的文案
_this.on('touchstart', function(){//为此图标绑定事件
$('.pop-tips').remove();
var popTips = $('<div class="pop-tips"></div>');
var popContent = $('<p><span>' + text + '</span></p>');
popTips.append(popContent).appendTo(_body);
var arrThisOffset = getElementOffset(_this);//获得此图标的距离页面顶端的距离和左边的距离
var arrTipOffset = [popTips.width(),popTips.height()]//获得tip的宽高
var tipFinalOffset = [
arrThisOffset[0] - (arrTipOffset[0]/2) + (_this.width()/2),//图标上偏移距离-tip高度的一般
arrThisOffset[1] - arrTipOffset[1] - 10//图标左偏移距离-tip宽度的一般+图标宽度的一半
];
popTips.css({
'left': tipFinalOffset[0],
'top': tipFinalOffset[1] - 5
});
popTips.fadeIn('fast').animate({'top': tipFinalOffset[1],'opacity':1}, 200);
setTimeout(function(){
popTips.remove();
}, 3000)
})
});
},

/*
*清除所有pop弹层
*/
remove: function () {
$('.shadow, .pop-wrap, .pop-wrap-error, .pop-loading').remove();
}

};
/*
*修正元素的定位,使之绝对定位于页面中间
*@param e 目标元素
*/
function popOffset (e){
var popHeight = e.height();
var popWidth = e.outerWidth();
e.css({'margin-top': -popHeight / 2, 'margin-left': -popWidth / 2});
}
/*
*修正元素的X轴定位,使之X轴绝对定位于页面中间
*@param e 目标元素
*/
function popOffsetX (e){
var popWidth = e.outerWidth();
e.css({'margin-left': -popWidth / 2});
}
/*
*返回元素距离页面顶端的距离和左边的距离
*@param e 目标元素
*@return array [左边距,顶边距]
*/
function getElementOffset(e){
return [e.offset().left,e.offset().top];
}
//渲染时初始化
$(function(){
if ($('.icon-question-circle').length > 0) {//按需加载
pop.tips();
};
})

CSS:

.pop-wrap{
position: fixed;
left: 50%;
top: 50%;
z-index: 102;
width: 80%;
margin-left: -40%;
background: #fff;
border-radius: 10px;
text-align: center;
display: none;
}
.pop-wrap .pop-content{
margin: 20px 20px 0;
border-bottom: 1px solid #ccc;
}
.pop-wrap .pop-content .pop-title{
font-size: 15px;
color: #333;
margin-bottom: 10px;
}
.pop-wrap .pop-content .pop-describe{
font-size: 13px;
color: #666;
margin-bottom: 10px;
}
.pop-wrap .pop-content .pop-describe b{
color: #f90;
}
.pop-wrap .pop-button-box{
overflow: hidden;
}
.pop-wrap .pop-button-box .pop-button{
float: left;
margin: 10px 0;
font-size: 17px;
color: #808;
}
.pop-wrap .pop-button-box .pop-button-single{
width: 100%;
}
.pop-wrap .pop-button-box .pop-button-double{
width: 50%;
border-left: 1px solid #ccc;
margin-left: -1px;
}

M端错误提醒 -- pop 使用的更多相关文章

  1. jQuery MiniUI开发系列之:Ajax处理超时、服务端错误

    MiniUI所有组件的ajax交互,均使用标准.成熟的jQuery.ajax. 依赖于jquery ajax组件的完善性,我们可以拦截住每一次ajax请求处理. 比如,拦截ajax返回数据前,判断返回 ...

  2. vscode写python时的代码错误提醒和自动格式化

    python的代码错误检查通常用pep8.pylint和flake8,自动格式化代码通常用autopep8.yapf.black.这些工具均可以利用pip进行安装,这里介绍传统的利用pip.exe安装 ...

  3. Dubbo消费端错误: ClassNotFoundException: org.apache.zookeeper.proto.WatcherEvent

    出现错误的原因是消费端war没有启动成功, 但是zkClient和Dubbo的对应Thread启动了, web container无法加载对应的类, INFO: Initializing Protoc ...

  4. thinkphp 字段静态验证$_validate中错误提醒多语言化写成{%LANGUATE}的原因

    class UserModel extends Model{ protected $_validate =  array( array('account', 'require', '{%LANGUAG ...

  5. mysql远程连接错误提醒:2013-Lost connection to MySQL server at ‘reading initial communication packet', system error: 0

    因为没有匹配/etc/hosts.allow. 解决方法: 1.在hosts.allow 文件中添加 mysqld:ALL [root@ucDB204 ~]# cat /etc/hosts.allow ...

  6. dotnetnuk错误提醒机制

    DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, "关注保存出错.", DotNetNuke.UI.Skins.Controls.Mo ...

  7. 【事件中心 Azure Event Hub】关于EventHub中出现Error时候的一些问题(偶发错误,EventHub后台升级,用户端错误,Retry机制的重要性)

    请问对偶发的定义是多少频率? 针对偶发的定义,主要是看发生的时间非常短,次数极少(如 10次以内),并且发生的时候EventHub其他分区或其他连接都是正常接收和发送数据.所以对于频率是没有明确的定义 ...

  8. MVC扩展Filter,通过继承HandleErrorAttribute,使用log4net或ELMAH组件记录服务端500错误、HttpException、Ajax异常等

    □ 接口 public interface IExceptionFilter{    void OnException(ExceptionContext filterContext);} Except ...

  9. 基于SS5服务端的Socks5客户端

    SS5停止更新已经好几年了,用作socks5代理的服务端还是比较稳定的.但是如果要使用加密账号和密码的协议,有些坑需要去填. 1.服务端的账号密码验证方式配置为“s”时,客户端进行协议验证时,需要用“ ...

随机推荐

  1. 算法笔记--sg函数详解及其模板

    算法笔记 参考资料:https://wenku.baidu.com/view/25540742a8956bec0975e3a8.html sg函数大神详解:http://blog.csdn.net/l ...

  2. Jersey 2.x 运行项目

    现在我们已经有可以可以运行的项目了,让我们队这个项目进行一些测试吧. 你需要运行下面的一些命令行: mvn clean test 这个命令将会对项目进行编译后运行单元测试. 你应该会看到和下面类似的输 ...

  3. Confluence 6 LDAP 连接池配置参数

    初始连接池大小(Initial Pool Size) 当初始化 LDAP 连接池的时候初始化创建的 LDAP 连接数量. 1 期望的连接池大小(Preferred Pool Size) 优化连接池的大 ...

  4. Confluence 6 连接到一个 LDAP 目录

    https://www.cwiki.us/display/CONFLUENCEWIKI/Connecting+to+an+LDAP+Directory

  5. entest1

      1◆ ai I   2◆ ai I ir ɜː ie i:   3◆ u: ʌ ɜː ə   ui u: ure ʊə

  6. 如何解决请求URL长度超过配置的maxurlLength值问题

    当我们批量请求的数据太多时,会出现请求的url长度超过配置maxurllength值的问题(比如一次性操作1000条数据) 1.问题描述: 我在进行批量选择单据进行发送时,出现这个问题(批量500条) ...

  7. laravel中的DB facade实现数据的CURD

    /* $students=DB::select("select * from student"); var_dump($students);*/ //新增数据: /*$bool=D ...

  8. SQL Server 调优系列玩转篇一(如何利用查询提示(Hint)引导语句运行)

    前言 前面几篇我们分析了关于SQL Server关于性能调优的一系列内容,我把它分为两个模块. 第一个模块注重基础内容的掌握,共分7篇文章完成,内容涵盖一系列基础运算算法,详细分析了如何查看执行计划. ...

  9. C# 接收form表单中多个相同name值的问题

    以前接收form表单的值直接用FormCollection或自定义类来接收,当有多个相同Name的值时会自动用“,”隔开,这样就有了一个问题,当值中本身就含有“,”时就比较难处理了. 所以解决方法就是 ...

  10. sgu 129 Inheritance 凸包,线段交点,计算几何 难度:2

    129. Inheritance time limit per test: 0.25 sec. memory limit per test: 4096 KB The old King decided ...