jq弹出框封装

北城余情 提交于 2020-01-25 00:23:25

 <!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <meta http-equiv="X-UA-Compatible" content="ie=edge">
 <title>弹出框</title>
</head>
<script src="https://cdn.bootcss.com/jquery/3.3.0/jquery.min.js"></script>
<style type="text/css">
    *{
    margin: 0;
    padding: 0;
    }
    body,html{
        margin: 0;
        padding: 0;
        width: 100%;
        height: 100%;
    }
    .addson{
        opacity:0;
        position:fixed;
        top:40%;
        left:40%;
        z-index: 9999;
        min-width:260px;
        max-width:260px;
        min-height:100px;
        margin:auto;
        background:#fff;
        border-radius:2px;
        color: #000;
        -moz-box-shadow:0px 0px 14px #858585;
        -webkit-box-shadow:0px 0px 14px #858585; 
        box-shadow:0px 0px 14px #858585;
    }
    .title{
        padding: 0 80px 0 20px;
        height: 42px;
        line-height: 42px;
        border-bottom: 1px solid #eee;
        font-size: 14px;
        color: #333;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        background-color: #F8F8F8;
        border-radius: 2px 2px 0 0;
        position: relative;
    }
    .close{
        position: absolute;
        right: 15px;
        font-size: 15px;
        cursor:pointer;
    }
    .content{
        padding:10px;
        word-break: break-all; 
        overflow: hidden; 
        font-size: 16px;
        overflow-x: hidden;
        overflow-y: auto;
    }
    .addConfirm{
        border-color: #1E9FFF;
        background-color: #1E9FFF;
        color: #fff;
        height: 28px;
        line-height: 28px;
        margin: 5px 5px 0;
        padding: 0 15px;
        border: 1px solid #dedede;
        border-radius:3px;
        font-weight: 400;
        cursor: pointer;
        text-decoration: none;
    }
    .closeCancel{
        height: 28px;
        line-height: 28px;
        margin: 5px 5px 0;
        padding: 0 15px;
        border: 1px solid #dedede;
        background-color: #fff;
        color: #333;
        border-radius:3px;
        font-weight: 400;
        cursor: pointer;
        text-decoration: none;
    }
    .btn{
        text-align: right;
        padding: 0 15px 12px;
    }
</style>
<body>
<button class="trigger">弹出框</button>
</body>
<script type="text/javascript">
$(function(){
    CDK={
        cfm:function(content, resFun,errFun, isType){
            var confirm=document.createElement('div');
            confirm.setAttribute('style','position:fixed;top:0;left:0;width: 100%;height: 100%;z-index:99;background-color: rgba(0, 0, 0,0.3);');
            $(confirm).addClass('confirmkuang');
            var str = `<div class="addson"><div class='title'>提示框<span class="closealter close">&#10006</span></div>`;
            str+=`<p class='content'>`+content+`</p>`;
            if(isType){
                str+=`<div class='btn'><button class="closealter addConfirm">确认</button><button class="closealter closeCancel">取消</button></div></div>`;
            } else {
                str+=`<div class='btn'><button class="closealter closeCancel">取消</button></div></div>`;
            }
            $(confirm).html(str)
            $("body").append(confirm);
            $('.addson').animate({'opacity':'1'}, 200)
            $('.addConfirm').on('click',function(){
                if (resFun){
                    resFun();
                }
            })
            $('.closealter').on('click',function(event){
                $('.addson').animate({'opacity':'0'}, 200)
                setTimeout(function(){
                    $('.confirmkuang').remove()
                }, 200)
            })
        }
    }
    $('.trigger').on('click',function(){
        CDK.cfm('确定要提交吗?',res=>{
            console.log('aa')
        },err=>{
            return
        }, true)
    })
})
</script>
</html>

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!