toastr简单用法及修改垂直居中

toastr是一个基于Jquery简单、漂亮的消息提示插件,使用简单、方便,可以根据设置的超时时间自动消失。

1、使用很简单,首选引入toastr的js、css文件
html

<script src="<%=path%>/res/toastr/toastr.min.js"></script>
<link rel="stylesheet" href="<%=path%>/res/toastr/toastr.min.css">

2、集成使用

//常规消息提示,默认背景为浅蓝色  
toastr.info("你有新消息了!");  
//成功消息提示,默认背景为浅绿色
toastr.success("你有新消息了!");  
//警告消息提示,默认背景为橘黄色
toastr.warning("你有新消息了!");  

  

//错误消息提示,默认背景为浅红色
toastr.error("你有新消息了!");  
//带标题的消息框
toastr.success("你有新消息了!","消息提示");  
//另一种调用方法
toastr["info"]("你有新消息了!","消息提示") 


3、自定义用法
通过设置自定义参数,可达到不同的效果

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

4、默认的放置位置positionClass只有上top下bottom,并没有垂直居中

oast-top-left 顶端左边 
toast-top-right 顶端右边
 toast-top-center 顶端中间
 toast-top-full-width 顶端,宽度铺满整个屏幕 
toast-botton-right
 toast-bottom-left
 toast-bottom-center
 toast-bottom-full-width

这时候,我们需要去原生的css中添加以下代码,

  .toast-center-center {
           top: 50%;
           left: 50%;
           margin-top: -30px;
           margin-left: -150px;
        }

在应用的时候,把默认positionClass的值修改为.toast-center-center,这样就可以水平垂直都居中啦~

toastr.options.positionClass = 'toast-center-center';

5、总结

  toastr作为一个提示框,真的是非常的简单,默认样式也很nice,值得使用。


---------------------
作者:
来源:CSDN
原文:https://blog.csdn.net/nuomizhende45/article/details/84205977
版权声明:本文为博主原创文章,转载请附上博文链接!

原文地址:https://www.cnblogs.com/4job/p/10125812.html