重写alert,自定义js中alert,美化alert

为了去除alert里的域名我们可以选择重写的方法,引入下面的css和js之后,直接调用alert便可

1.css内容:

html,body{height:100%;}
    .con{
     position: fixed;
      top: 0;
      left: 0;
      bottom: 0;
      right: 0;
      background-color: rgba(0, 0, 0, 0.5);
    }
    #msg{
        position:fixed;
        top:25%;
        left:40%;
    }
    .info_message {
        color: #000;
        background: rgb(255, 255, 255);
        height: 160px;
        display: inline-block;
        width:350px;
        border-radius: 15px;
    }
    #alertSure{
        position:absolute;
        bottom: 5%;
        right:5%;
        width: 60px;
        height: 30px;
        text-align: center;
        line-height: 30px;
        background: #2e9cce;
        color: #fff;
        cursor:pointer;
        border-radius:5px;
    }


    .detail_message{
        width:325px;
        height:115px;
        overflow: hidden;
        display:inline-block;
        padding:10px;
        font-size: 18px;
        margin-left:15px;
        color:#000000;
    }
    .message-button{
        display: inline-block;
        text-align: right;
        float: right;
    }
    #alertSure:hover,#alertCancel:hover{
            background:rgba(118, 206, 247, 0.88);
    }
    .alertTitle{
        padding: 0 80px 0 20px;
        height: 40px;
        line-height: 40px;
        border-bottom: 1px solid #F0F0F0;
        font-size: 16px;
        font-weight: bold;
        color: #000000;
        overflow: hidden;
        border-radius: 2px 2px 0 0;
    }
    


.closeAlert {
  position: relative;
  display: inline-block;
  height: 20px;
  font-weight: normal;
  cursor: pointer;
  color: initial; /*取消继承父元素的颜色属性*/
    font-weight: normal;
}


.closeAlert::before,
.closeAlert::after {
    color: initial; /*取消继承父元素的颜色属性*/
font-weight: normal;
  position: absolute;
  content: '';
  width: 2px;
  height: 16px;
  background-color: rgb(162, 162, 164);
  top: 8px;
  left: 268px;
  transform: rotate(45deg);
}

.closeAlert::after {
  transform: rotate(-45deg);
}

.closeAlert:hover::before,
.closeAlert:hover::after {
  background-color: #000 !important;
}

2.js内容

function alert(e){

    // $("body").append("<div id='msg'><span>"+e+"</span></div>");

    var html="";

     html+="<div class='con'><div id='msg'>";

     html+="<div class='info_message'>";

     html+="<div class='alertTitle'>提示<span class='closeAlert'></span></div>";

     html+="<span class='detail_message'>"+e+"</span>";

     html+="</div><div id='alertSure'>确定</div></div></div>";

    $('body').append(html);

    clearmsg();

}

function clearmsg(){

 

    $('#alertSure').click(function(){

     $("#msg").remove();

     $('.con').remove();

    })

 

  $('.closeAlert').click(function(){

     $("#msg").remove();

     $('.con').remove();

    })

};

3.效果展示

a378ccb9fc9249b5864b27a588e7a0b2.png

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值