最近总想着写一个模拟alert和confirm插件,代替原生的
github: https://github.com/tong-mikasa/msgbox-confirm
主要js代码,scss代码
(function($) {
    $.MsgBox = {
        Alert: function (title, msg, callback) {
            this._generateMsgboxHtml("alert", title, msg);
            //$("body").append(Handlebars.compile(this._tplMsgHtm)({type: "alter", title: title, msg: msg}));
            this._btnMsgOk(callback);
        },
        Confirm: function (title, msg, callback,cancelCallback) {
            this._generateMsgboxHtml("confirm", title, msg);
            //$("body").append(Handlebars.compile(this._tplMsgHtm)({type: "confirm", title: title, msg: msg}));
            this._btnMsgOk(callback);
            this._btnMsgNo(cancelCallback);
        },
        CustomizeConfirm: function (title, msg, leftButtonText,rightButtonText,callback,cancelCallback) {
            this._generateMsgboxHtml("confirm", title, msg,leftButtonText,rightButtonText);
            //$("body").append(Handlebars.compile(this._tplMsgHtm)({type: "confirm", title: title, msg: msg}));
            this._btnMsgOk(callback);
            this._btnMsgNo(cancelCallback);
        },
        _tplMsgHtm: $("#tpl_confirm_msgbox").html(),
        _btnMsgOk: function(callback) {
            var that = this;
            $("#msg_btn_ok").click(function () {
                that._removeMsgboxPopupWrap();
                if (callback && typeof (callback) == 'function') {
                    callback();
                }
            });
        },
        _btnMsgNo: function(cancelCallback) {
            var that = this;
            $("#msg_btn_no").click(function () {
                that._removeMsgboxPopupWrap();
                if (cancelCallback && typeof (cancelCallback) == 'function') {
                    cancelCallback();
                }
            });
        },
        _generateMsgboxHtml: function (type, title, msg,leftButtonText,rightButtonText) {
            var okButtonText = (typeof leftButtonText == "undefined") ? '确定' : leftButtonText
                , noButtonText = (typeof rightButtonText == "undefined")  ? '取消': rightButtonText;
            var strHtm ='<div class="confirm-msgbox-popup-wrap">' +
                '            <div class="confirm-mask-bg"></div>' +
                '            <div id="confirm_content_wrap">' +
                '                <div class="msg-in">' +
                '                    <div id="msg_header" class="text-center">' +
                '                        <span id="msg_title">'+title+'</span>' +
                '                    </div>' +
                '                    <div id="msg_msg" class="text-center">' + msg + '</div>' +
                '                    <div id="msg_btn_wrap" class="text-center">';
            if(type == "alert")
            {
                strHtm += '<span id="msg_btn_ok" class="msg-btn cursor-point col-full">'+okButtonText+'</span>';
            }
            if(type == "confirm"){
                strHtm += '<span id="msg_btn_ok" class="msg-btn cursor-point col-half">'+okButtonText+'</span>';
                strHtm +='<span id="msg_btn_no" class="msg-btn cursor-point col-half">'+noButtonText+'</span>';
            }
            strHtm +='           </div>' +
                '                </div>' +
                '            </div>' +
                '        </div>';
            this._removeMsgboxPopupWrap();
            $("body").append(strHtm);
        },
        _removeMsgboxPopupWrap: function(){
            $(".confirm-msgbox-popup-wrap").remove();
        }
    };
})(jQuery);
/*
<script type="text/x-handlebars-template" id="tpl_confirm_msgbox">
    <div class="confirm-msgbox-popup-wrap">
        <div class="confirm-mask-bg"></div>
        <div id="confirm_content_wrap">
            <div class="msg-in">
                <div id="msg_header" class="text-center">
                    <span id="msg_title">{{title}}</span>
                </div>
                <div id="msg_msg" class="text-center">
                    {{msg}}
                </div>
                <div id="msg_btn_wrap" class="text-center">
                    {{#ifCond type '==' 'alert'}}
                    <span id="msg_btn_ok" class="msg-btn cursor-point col-full">xxx</span>
                    {{/if}}
                    {{#ifCond type '==' 'confirm'}}
                    <span id="msg_btn_ok" class="msg-btn cursor-point col-half">xxx</span>
                    <span id="msg_btn_no" class="msg-btn cursor-point col-half">xxx</span>
                    {{/ifCond}}
                </div>
            </div>
        </div>
    </div>
</script>
*/
.confirm-msgbox-popup-wrap{
    position: fixed;
    left: 0;
    top: 0;
    z-index: 9990;
    width: 100%;
    height: 100%;
    .col-full{
        width: 100%;
    }
    .col-half{
        width: 50%;
    }
    .cursor-point{
        cursor: pointer;
    }
    .confirm-mask-bg{
        position: absolute;
        z-index: 9991;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;
        background: rgba(0, 0, 0, 0.8);
    }
    #confirm_content_wrap{
        position: absolute;
        z-index: 9999;
        left: 50%;
        top: 50%;
        width: 400px;
        height: 250px;
        margin: -125px 0 0 -200px;
        .msg-in{
            background: #ffffff;
            border-radius: 14px;
            -webkit-border-radius: 14px;
            -moz-border-radius: 14px;
        }
        #msg_header{
            padding-top: 15px;
            border-top-left-radius: inherit;
            border-top-right-radius: inherit;
        }
        #msg_title{
            color: #333333;
            text-align: center;
            padding: 10px 0 10px;
            font-size: 20px;
            font-weight: bold;
        }
        #msg_msg{
            color: #000000;
            padding: 20px;
            vertical-align: middle;
            font-size: 16px;
            line-height: 1.4;
            max-height: 100px;
            overflow-y: auto;
        }
        #msg_btn_wrap{
            border-top: 1px solid #e6e6e5;
        }
        .msg-btn{
            padding-top: 12px;
            padding-bottom: 12px;
            display: inline-block;
            font-size: 15px;
            color: #ffffff;
            border: none;
            border-right: 1px solid #e6e6e5;
            &:last-child{
                border: none;
            }
        }
        #msg_btn_ok{
            color: #0079FF;
        }
        #msg_btn_no{
            color: rgba(0, 0, 0, 0.9);
        }
    }
}
@media screen and (max-width: 1000px) {
    .confirm-msgbox-popup-wrap{
        #confirm_content_wrap{
            left: 10%;
            right: 10%;
            width: auto;
            margin: -125px 0 0 0;
            #msg_title{
                font-size: 30px;
            }
            #msg_msg{
                padding: 30px;
                font-size: 28px;
            }
            .msg-btn{
                padding-top: 20px;
                padding-bottom: 20px;
                font-size: 28px;
            }
        }
    }
}
最近总想着写一个模拟alert和confirm插件,代替原生的的更多相关文章
- [转]jQuery插件实现模拟alert和confirm
		本文转自:http://www.jb51.net/article/54577.htm (function () { $.MsgBox = { Alert: function (title, msg) ... 
- 模拟alert和confirm
		啥也不说,先上图,有图有真相 :) 现在绝大多数网站都不用自带的alert和confirm了,因为界面太生硬了.因此这个插件就这样产生了... 来看插件的实现代码吧: (function () { $ ... 
- 自编jQuery插件实现模拟alert和confirm
		现在绝大多数网站都不用自带的alert和confirm了,因为界面太生硬了.因此这个插件就这样产生了自己定制一个的想法...... 啥也不说,先上图,有图有真相 :) 现在绝大多数网站都不用自带的al ... 
- 从0开始写一个简单的vite hmr 插件
		从0开始写一个简单的vite hmr 插件 0. 写在前面 在构建前端项目的时候,除开基本的资源格式(图片,json)以外,还常常会需要导入一些其他格式的资源,这些资源如果没有第三方vite插件的支持 ... 
- 模拟alert,confirm  阻塞状态
		/*** * 模拟alert弹窗 * content 为弹框显示的内容 * 确定按钮对应的下面取消关闭显示框 * **/function oAlert(content) { var oWrap = $ ... 
- CSS写一个圣诞树Chrome浏览器小插件
		一时兴起,突然想写一个Chrome浏览器插件,不知道写啥,就写了一个圣诞树小插件.项目源码>> Chrome浏览器插件 Chrome浏览器插件最主要的是:index.html.manife ... 
- 手写一个模拟的ReentrantLock
		package cn.daheww.demo.juc.reentrylock; import sun.misc.Unsafe; import java.lang.reflect.Field; impo ... 
- 用 python 写一个模拟玩家移动的示例
		实例:二维矢量模拟玩家移动 在游戏中,一般使用二维矢量保存玩家的位置,使用矢量计算可以计算出玩家移动的位置,下面的 demo 中,首先实现二维矢量对象,接着构造玩家对象,最后使用矢量对象和玩家对象共同 ... 
- JS模拟Alert与Confirm对话框
		这2个例子都是用原生JS写的,主要是用JS拼接了界面,并未做过多的事件监听.,样式用了Css3的一些特性. 调用方式则为: //Alert Alert.show('我警告你哦~'); //Confir ... 
随机推荐
- 利用predis操作redis方法大全
			predis是PHP连接Redis的操作库,由于它完全使用php编写,大量使用命名空间以及闭包等功能,只支持php5.3以上版本,故实测性能一般,每秒25000次读写. 将session数据存放到re ... 
- up7-文件保存位置
			asp.net 默认位置:项目/upload/年/月/日/guid/ 代码截图: 位置截图: jsp 默认位置:tomcat/webapps/Uploader7Oracle/upload/年/月/ ... 
- 执行“hdfs dfs -ls”时报ConnectException
			原因可能是指定的端口号不对,该端口号由hdfs-site.xml中的属性"dfs.namenode.rpc-address"指定,即为NameNode的RPC服务端口号. 文件上传 ... 
- .NET基础 (05)内存管理和垃圾回收
			内存管理和垃圾回收1 简述.NET中堆栈和堆的特点和差异2 执行string abc="aaa"+"bbb"+"ccc"共分配了多少内存3 ... 
- 编写高质量代码改善C#程序的157个建议——建议71:区分异步和多线程应用场景
			建议71:区分异步和多线程应用场景 初学者有时候会将异步和多线程混为一谈.如果对它们之间的区别不是很清楚,很容易写出下面这样的代码: private void buttonGetPage_Click( ... 
- 重叠IO
			一. 异步IO 说到重叠模型首先还是提一下异步IO比较好,因为从本质上讲,重叠模型也是一种异步IO模型. 我们知道,相对于计算机执行的其他操作而言,设备IO(文件.管道.套接 ... 
- log4j.properties加入内容
			log4j.rootLogger=INFO, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender. ... 
- Transaction And Lock--存储过程中使用事务的模板
			某公司内部使用的模板 create procedure [usp_my_procedure_name] as begin set nocount on; declare @trancount int; ... 
- Linux中VMware虚拟机增加磁盘空间的扩容操作
			用VMwareware虚拟机安装的Red Hat Enterprise Linux系统剩余空间不足,造成软件无法正常安装.如果重新装一遍系统就需要重新配置好开发环境和软件的安装配置.通过上网搜集的资料 ... 
- python学习之路 七 :生成器、迭代器
			本节重点: 掌握列表生成式.生成器.迭代器 一.生成式 现在有个需求,把[1,2,3,4,5,6,7,8,9,10]中的每个值加1. # 二逼青年版 a = [0,1,2,3,4,5,6,7,8,9 ... 
