M端错误提醒 -- pop 使用
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 使用的更多相关文章
- jQuery MiniUI开发系列之:Ajax处理超时、服务端错误
MiniUI所有组件的ajax交互,均使用标准.成熟的jQuery.ajax. 依赖于jquery ajax组件的完善性,我们可以拦截住每一次ajax请求处理. 比如,拦截ajax返回数据前,判断返回 ...
- vscode写python时的代码错误提醒和自动格式化
python的代码错误检查通常用pep8.pylint和flake8,自动格式化代码通常用autopep8.yapf.black.这些工具均可以利用pip进行安装,这里介绍传统的利用pip.exe安装 ...
- Dubbo消费端错误: ClassNotFoundException: org.apache.zookeeper.proto.WatcherEvent
出现错误的原因是消费端war没有启动成功, 但是zkClient和Dubbo的对应Thread启动了, web container无法加载对应的类, INFO: Initializing Protoc ...
- thinkphp 字段静态验证$_validate中错误提醒多语言化写成{%LANGUATE}的原因
class UserModel extends Model{ protected $_validate = array( array('account', 'require', '{%LANGUAG ...
- 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 ...
- dotnetnuk错误提醒机制
DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, "关注保存出错.", DotNetNuke.UI.Skins.Controls.Mo ...
- 【事件中心 Azure Event Hub】关于EventHub中出现Error时候的一些问题(偶发错误,EventHub后台升级,用户端错误,Retry机制的重要性)
请问对偶发的定义是多少频率? 针对偶发的定义,主要是看发生的时间非常短,次数极少(如 10次以内),并且发生的时候EventHub其他分区或其他连接都是正常接收和发送数据.所以对于频率是没有明确的定义 ...
- MVC扩展Filter,通过继承HandleErrorAttribute,使用log4net或ELMAH组件记录服务端500错误、HttpException、Ajax异常等
□ 接口 public interface IExceptionFilter{ void OnException(ExceptionContext filterContext);} Except ...
- 基于SS5服务端的Socks5客户端
SS5停止更新已经好几年了,用作socks5代理的服务端还是比较稳定的.但是如果要使用加密账号和密码的协议,有些坑需要去填. 1.服务端的账号密码验证方式配置为“s”时,客户端进行协议验证时,需要用“ ...
随机推荐
- boosting方法
概述 Boosting基本思想: 通过改变训练数据的概率分布(训练数据的权值分布),学习多个弱分类器,并将它们线性组合,构成强分类器. Boosting算法要求基学习器能对特定的数据分布进行学习,这可 ...
- RabbitMQ入门_10_队列长度限制
参考资料:https://www.rabbitmq.com/maxlength.html RabbitMQ 有两种方式限制队列长度,第一种是对队列中消息总数进行限制: gordon.study.rab ...
- Lua面向对象 --- 封装
工程结构: Player.lua: Player = {} function Player:new() local self = {} setmetatable(self, {__index = Pl ...
- SpringBoot+Mybatis-Generator自动生成
原文链接 1.版本 Spring Boot 1.5.10 mybatis-generator-core 1.3.5 mybatis-generator-maven-plugin 1.3.5 2.项目目 ...
- Android之设计模式
设计模式的概念 1.基本定义:设计模式(Design pattern)是一套被反复使用的代码设计经验的总结.使用设计模式的目的是为了可重用代码.让代码更容易被他人理解.设计模式是是软件工程的基石脉络, ...
- 『Glob』常用方法记录
glob.glob(file) 返回匹配的文件 glob.glob(./flower_photos/tulips/*.jpg) Out[1]:<br># ['./flower_photos ...
- CentOS服务器安装FFmpeg指南
CentOS服务器安装FFmpeg指南 服务器系统环境为:CentOS 6.5(final): 在服务器成功安装FFmpeg颇废了一番功夫,总结一下成功安装的过程,希望对大家有用 ^_^ : Ps:使 ...
- python-day46--前端基础之html
一.html是什么? 超文本标记语言(Hypertext Markup Language,HTML)通过标签语言来标记要显示的网页中的各个部分.一套规则,浏览器认识的规则 浏览器按顺序渲染网页文件,然 ...
- ubuntu安装环境软件全文档
1,安装apace2: sudo apt-get install apache2 2谷歌浏览器的安装:sudo apt-get install chromium-browser-dbg 3,国际版Q ...
- zzuli1985(dp/水dfs郑轻比赛)
再一次感受到dp的威力 1985: 即将到来的新生赛 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 112 Solved: 28 SubmitStat ...