Jquery toastr提示框

toastr是一个基于JQuery的消息提示插件;


1. 下载toastr和jquery

https://jquery.com/download/

https://codeseven.github.io/toastr/

2. 引入jquery和toastr

<script src="./resources/jquery-3.3.1.min.js"></script>
<script src="../resources/js/toastr/toastr.min.js"></script>
<link rel="stylesheet" href="../resources/css/toastr/toastr.min.css" />

3. 配置提示框,通过自定义配置,达到不同的效果


toastr.options = {  

        closeButton: false,  
        debug: false,  
        progressBar: true,  
        positionClass: "toast-bottom-center",  
        onclick: null,  
        showDuration: "300",  
        hideDuration: "1000",  
        timeOut: "2000",  
        extendedTimeOut: "1000",  
        showEasing: "swing",  
        hideEasing: "linear",  
        showMethod: "fadeIn",  
        hideMethod: "fadeOut"  

    };

参数说明

closeButton:false,是否显示关闭按钮(提示框右上角关闭按钮);
debug:false,是否为调试;
progressBar:false,是否显示进度条(设置关闭的超时时间进度条);
positionClass,消息框在页面显示的位置


  toast-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

onclick,点击消息框自定义事件
showDuration: “300”,显示动作时间
hideDuration: “1000”,隐藏动作时间
timeOut: “2000”,自动关闭超时时间
extendedTimeOut: “1000”
showEasing: “swing”,
hideEasing: “linear”,
showMethod: “fadeIn” 显示的方式,和jquery相同
hideMethod: “fadeOut” 隐藏的方式,和jquery相同

4. 根据不同提示使用不同的提示框;

格式: toastr.消息类型方法('消息标题;可省略', '消息内容') /// toastr['消息类型方法']('消息标题;可省略', '消息内容')

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

posted @ 2018-10-28 20:08  Zero_追梦  阅读(1946)  评论(0编辑  收藏  举报