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”时,客户端进行协议验证时,需要用“ ... 
随机推荐
- air for android 使用ANE来获取安卓手机IMEI号
			一首页创建一个ANE文件 1 使用FlashBuilder 或者Eclipse 创建一个新的android项目 A 创建文件Extension.java package com.dabing. ... 
- HDU 6015 Skip the Class
			Skip the Class 代码: #include<bits/stdc++.h> using namespace std; #define ll long long #define l ... 
- nodejs 监听文件夹变化的模块
			使用Node.JS监听文件夹变化 fs.watch 其中Node.JS的文件系统也可侦听某个目录的改变, 如fs.watch 其中fs.watch的最大缺点就是不支持子文件夹的侦听,并且在很多情况 ... 
- smarty课程---smarty3的安装和使用
			smarty课程---smarty3的安装和使用 一.总结 一句话总结:smarty 是什么,就不多说了,用过php,接触过php的人都对smarty 再熟悉不过了.它是一个很强大的代码分离软件,作为 ... 
- Hibernate实例
			Hibernate实例 一.Hibernate简介 Hibernate是简化项目中连接数据库的一个框架工具 Hibernate是Java领域类技术成熟稳定的ORM框架 * ORM是对象关系映射 * 使 ... 
- 12月7日,几个错误,拼写错误,遗漏符号:,记忆有误,max-width的作用。gem mini_magick, simple_form
			❌: 1. /Users/chentianwei/jdstore3/jdstore/config/routes.rb:6:in `block in <top (required)>': u ... 
- dubbo监控报错Error creating bean with name 'uriBrokerService'
			在jdk1.8下面会出现此错误 解决方法: 1.更换服务器jdk版本.(会影响其他项目环境) 2.修改dubbo-admin tomcat默认jdk版本. 3.修改dubbo-admin项目依赖(de ... 
- dp练习(11)——石子并归
			1048 石子归并 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 有n堆石子排成一列,每堆石子有一个重量w ... 
- Generate PDF in Sourcing through concurrent request,在EBS java并发中调用指定am的方法
			package oracle.apps.pon.printing.cp; import java.io.InputStream; import java.io.FileOutputStream; im ... 
- jQuery 插件运行机制和 $冲突解决
			1.jQuery.fn.extend(object) 基本插件假设我们要创建一个插件,使一组元素中的文本变为绿色.我们要做的就是添加一个名为greenify的函数, $.fn 将像其他任何jquery ... 
