弹框

html

<div id="alertWin" style="display: none;">
    <div class="alertCloser cssAlertCloser">
    </div>
    <div style="position:absolute;left:50%;top:50%;width:5px;height:5px;z-index: 21;">
        <div class="alertContent cssAlertContent">
            <div class="h1 title">提示:</div>
            <div id="alertWin-content"></div>
            <div id="alertWin-oper" style="text-align: center">
                <div onclick="closeAlert();">关闭</div>
            </div>
        </div>
    </div>
</div>

js

    function closeAlert(){
        document.getElementById("alertWin").style.display="none";
    }
    function openAlert(msg){
        document.getElementById("alertWin-content").innerText=msg;
        document.getElementById("alertWin-oper").style.display="block";
        document.getElementById("alertWin").style.display="block";
    }
    function showProcess(){
        document.getElementById("alertWin-content").innerText='';
        document.getElementById("alertWin-oper").style.display="none";
        document.getElementById("alertWin").style.display="block";
    }
    function setAlertMsg(msg){
        document.getElementById("alertWin-content").innerText=msg;
    }

css

#alertWin {
  font-size: 16px;
}

#alertWin .centerPoint {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 5px;
  height: 5px;
  z-index: 21;
}

#alertWin .cssAlertCloser {
  height: 100%;
  position: fixed;
  top: 0px;
  left: 0px;
  right: 0px;
  z-index: 20;
  opacity: 0.3;
  background-color: rgb(13, 13, 13);
}

#alertWin .cssAlertContent {
  float: left;
  width: 300px;
  height: 160px;
  margin-left: -150px;
  margin-top: -100px;
  background-color: white;
  border-radius: 8px;
}

#alertWin .cssAlertContent .title {
  height: 40px;
  line-height: 50px;
  border-bottom: 1px solid #f1f2f6;
  padding-left: 15px;
  color: #9b9ba6
}

#alertWin-content {
  height: 50px;
  color: rgb(118, 124, 140);
  padding: 10px 10px;
}

#alertWin-oper{
  text-align: center;
}

#alertWin-oper > div {
  display: inline-block;
  width: 150px;
  height: 25px;
  padding-top: 3px;
  font-size: 14px;
  color: white;
  border-radius: 5px;
  background-color: rgb(255, 104, 102);
}

综合方法

function openAlert(msg){
    if($("#alertWin").length>0){
        $("#alertWin").remove();
    }
    var html='<div id="alertWin"><div class="alertCloser cssAlertCloser" style="display: block;"></div>' +
        '<div class="centerPoint"><div class="alertContent cssAlertContent"><div class="h1 title">提示:</div>' +
        '<div id="alertWin-content">'+msg+'</div><div id="alertWin-oper"><div>关闭</div></div></div></div></div>';
    $("body").append(html);
    $("#alertWin .alertCloser").on("touchstart",function (e) {
        // 判断默认行为是否可以被禁用
        if (e.cancelable) {
            // 判断默认行为是否已经被禁用
            if (!e.defaultPrevented) {
                e.preventDefault();
            }
        }
    }).on("touchend",function (e) {
        $("#alertWin").remove();
    });
    $("#alertWin-oper>div").on("touchstart",function (e) {
        // 判断默认行为是否可以被禁用
        if (e.cancelable) {
            // 判断默认行为是否已经被禁用
            if (!e.defaultPrevented) {
                e.preventDefault();
            }
        }
    }).on("touchend",function (e) {
        $("#alertWin").remove();
    });
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值