首页 > 技术文章 > 如何将toastr提示框顶部 居中

qiao20 2021-11-12 16:14 原文

使用原生的toastr提示框提示语默认会出现在右上角现在想要居中,百度了以下提示框的属性发现有一个控制的属性positionClass

       toastr.options = {
 
            "closeButton": false, //是否显示关闭按钮
 
            "debug": false, //是否使用debug模式
 
            "positionClass": "toast-top-center",//弹出窗的位置
 
            "showDuration": "300",//显示的动画时间
 
            "hideDuration": "1000",//消失的动画时间
 
            "timeOut": "5000", //展现时间
 
            "extendedTimeOut": "1000",//加长展示时间
 
            "showEasing": "swing",//显示时的动画缓冲方式
 
            "hideEasing": "linear",//消失时的动画缓冲方式
 
            "showMethod": "fadeIn",//显示时的动画方式
 
            "hideMethod": "fadeOut" //消失时的动画方式
        };

positionClass官方给的可选属性是,发现并没有水平垂直居中的

现在要在它的原css文件中自定义一个css样式

  .toast-top-center {
           top: 16%;//自定义高度
           left: 50%;
           margin-top: -30px;
           margin-left: -150px;
        }

然后将我们的positionclss改成我们自定义的样式发现toastr提示框居中了

 

推荐阅读