js realizes the custom style of the alert box

insert image description here

  1. First render a style with css
#msg{
    
    
    height: 2rem;
    text-align: center;
    position: fixed;
    top: 50%;
    margin-top: -1rem;
    line-height: 2rem;
    width: 100%;
}
#msg span{
    
    
    color: #fff;
    background: #83C422;
    height: 2rem;
    display: inline-block;
    padding: 0 3rem;
    border-radius: 52px;
}
  1. js anonymous function, when using it, just use the alert event directly
<script>
	 function alert(e){
    
    
	     $("body").append("<div id='msg'><span>"+e+"</span></div>");
	     clearmsg();
	 }
	 function clearmsg(){
    
    
	     var t = setTimeout(function(){
    
    
	         $("#msg").remove();
	     },2000)
	 };
 </script>
  1. Effectinsert image description here

Guess you like

Origin blog.csdn.net/weixin_44975322/article/details/124302776