纯js代码封装弹窗操作

纯js代码弹窗操作

function bigPopup(data, click) {
    var type = data.type;
    var msg = data.msg;
    var submsg = data.subMsg;
    var cancelBtnWord = data.cancelBtnWord;
    var confirmBtnWord = data.confirmBtnWord;
    let clickHandler = click || $.noop;
    let myClickHandler = function () {
        $('#bigAlert').remove();
        //错误或疑问时可进行回掉
        if (type == "error" || type == "question") {
            if (confirmBtnWord != null) {
                clickHandler($(this).html() == confirmBtnWord);
            }
        }
    };
    let init = function () {
        $bigAlert = $("<div id='bigAlert' style='width:100%;height:100%;background:rgba(0,0,0,0.5);z-index:1000;text-align: center;position:fixed;left:0;top:0;'></div>");
        $myalert = $("<div id='myalert' style='text-align: center;width: 400px; height: 240px; background-color: rgb(255, 255, 255); box-shadow: rgba(3, 0, 0, 0.16) 0px 0px 16px 0px; z-index: 2; position: fixed; top: 50%; left: 50%; margin-left: -200px; margin-top: -150px; overflow: hidden; display: block;'>").appendTo($bigAlert);

        let $divclose = $("<div id='close' style='width: 100%; height: 32px;'></div>").appendTo($myalert);
        let $imgclose = $("<img id='btn-close' src='static/image/popup/defultClose.png' style='margin:16px 0px 0px 360px;cursor: pointer;' onMouseOver=this.src='static/image/popup/floatClose.png' onmouseout=this.src='static/image/popup/defultClose.png' >").appendTo($divclose).click(myClickHandler);

        let $divpictureContent = $("<div id='pictureContent' style='display:inline-block;margin-top: 10px;'>").appendTo($myalert);
        // 根据type类型判断显示图片路径
        let imgpath;
        if (type == "success") {
            imgpath = "static/image/popup/bigSuccess.png";
        } else if (type == "error") {
            imgpath = "static/image/popup/bigError.png";
        } else if (type == "warring-1") {
            imgpath = "static/image/popup/bigWarring1.png";
        } else if (type == "warring-2") {
            imgpath = "static/image/popup/bigWarring2.png";
        } else if (type == "question") {
            imgpath = "static/image/popup/bigQuestion.png";
        }
        let $picture = $("<img id='picture' src=" + imgpath + ">").appendTo($divpictureContent);

        let $content = $("<div id='content' style='margin-top: 20px;'>").appendTo($myalert);
        let $msg = $("<div id='msg' style='text-align: center; font-family: MicrosoftYaHei; font-size: 18px; font-weight: normal; font-stretch: normal;'>" + msg + "</div>").appendTo($content);
        let $subMsg = $("<div id='subMsg' " +
            "style='text-align: center; " +
            "font-family: MicrosoftYaHei;" +
            " font-size: 14px; " +
            "font-weight: normal;" +
            " letter-spacing: 0px;" +
            " color: rgb(153, 153, 153);'>" + submsg + "</div>").appendTo($content);
        let $buttonlist = $("<div id='buttonlist' style='margin-top: 20px;'>").appendTo($myalert);
        //设置按钮内容(如果为警告,仅一个按钮)
        if ((type == "warring-1" || type == "warring-2") && cancelBtnWord != null) {
            $btnmid = $("<button type='button' id='btn-mid' " +
                "style='width: 108px;" +
                "height: 32px;" +
                "background-color: #ffffff;" +
                "border-style: solid;" +
                "border-width: 1px;" +
                "border-radius: 16px;" +
                "border-color: #1da4fe;" +
                "border-image-slice: 1;" +
                "margin-left: 146px;" +
                "font-family: MicrosoftYaHei;" +
                "font-size: 16px;" +
                "letter-spacing: 0px; + " +
                "opacity: 0.8;" +
                "cursor: pointer;" +
                "color: #0099ff;'>" + cancelBtnWord + "</button>").appendTo($buttonlist).click(myClickHandler);
        } else
        //(如果为疑问)
        if (type == "question") {
            //设置内容
            $btnquestionleft = $("<button id='btn-question-left' " +
                "style='width: 108px" +
                ";height: 32px" +
                ";border-width: 0px;" +
                "background-image: linear-gradient(90deg, #0fc1fc 0%, #1da4fe 100%),linear-gradient(#ffffff, #ffffff);" +
                "border-radius: 16px;" +
                "font-size: 16px;" +
                "letter-spacing: 0px;" +
                "color: #ffffff;" +
                "margin-left: 86px;" +
                "opacity: 0.8;" +
                "cursor: pointer;" +
                "float: left;'>" + confirmBtnWord + "</button>").appendTo($buttonlist).click(myClickHandler);
            $btnquestionright = $("<button id='btn-question-right' " +
                "style='width: 108px;" +
                "height: 32px;" +
                "background-color: #ffffff;" +
                "border-style: solid;" +
                "border-width: 1px;" +
                "border-radius: 16px;" +
                "border-color: #1da4fe;" +
                "border-image-slice: 1;" +
                "font-family: MicrosoftYaHei;" +
                "font-size: 16px;" +
                "letter-spacing: 0px;" +
                "color: #0099ff;" +
                "margin-left: 15px;" +
                "opacity: 0.8;" +
                "cursor: pointer;" +
                "float: left;'>" + cancelBtnWord + "</button>").appendTo($buttonlist).click(myClickHandler);
        }//其他情况,设置按钮内容
        else {
            $btnleft = $("<button id='btn-left' " +
                "style='width: 108px;" +
                "height: 32px;" +
                "background-color: #ffffff;" +
                "border-style: solid;" +
                "border-width: 1px;" +
                "border-radius: 16px;border-color: #1da4fe;" +
                "border-image-slice: 1;" +
                "margin-left: 86px;" +
                "font-family: MicrosoftYaHei;" +
                "font-size: 16px;" +
                "letter-spacing: 0px;" +
                "color: #0099ff;" +
                "opacity: 0.8;" +
                "cursor: pointer;" +
                "float: left;'>" + cancelBtnWord + "</button>").appendTo($buttonlist).click(myClickHandler);
            $btnright = $("<button class='bluebg1'  id='btn-right' " +
                "style='width: 108px;" +
                "height: 32px;" +
                "border-width: 0px;" +
                "background-image: linear-gradient(90deg, #0fc1fc 0%, #1da4fe 100%),linear-gradient(#ffffff, #ffffff);" +
                "border-radius: 16px;" +
                "font-size: 16px;" +
                "letter-spacing: 0px;" +
                "color: #ffffff;" +
                "margin-left: 15px;" +
                "opacity: 0.8;" +
                "cursor: pointer;" +
                "float: left;'>" + confirmBtnWord + "</button>").appendTo($buttonlist).click(myClickHandler);
        }
        $("body").append($bigAlert);
    };
    init();
}

传入data参数:
let data = {
“type”: “question”,
“msg”: “操作成功”,
“subMsg”: “保存路径:C:\User\Administrator”,
“cancelBtnWord”: “知道了”,“confirmBtnWord”: “确定”
};

调用方式:
$(“button”).click(function(){
assessLoad(data,function(f){
if(f){
//业务操作 ,处理其他业务逻辑
window.open(“http://www.baidu.com”);
}
});
})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

恒二哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值