1. 程式人生 > >Jquery消息提示插件toastr使用詳解

Jquery消息提示插件toastr使用詳解

toast null close ati lan 提示框 onclick posit dem

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、效果


技術分享

3、集成使用

 1 //常規消息提示,默認背景為淺藍色  
 toastr.info("你有新消息了!
");
2 //成功消息提示,默認背景為淺綠色 toastr.success("你有新消息了!");
3 //警告消息提示,默認背景為橘黃色 toastr.warning("你有新消息了!");
4 //錯誤消息提示,默認背景為淺紅色 toastr.error("你有新消息了!");
5 //帶標題的消息框 toastr.success("你有新消息了!","消息提示");
6 //另一種調用方法 toastr["info"]("你有新消息了!","消息提示");

4、自定義用法

通過設置自定義參數,可達到不同的效果

自定義參數:
JavaScript

 1
toastr.options = { 2 closeButton: false, 3 debug: false, 4 progressBar: true, 5 positionClass: "toast-bottom-center", 6 onclick: null, 7 showDuration: "300", 8 hideDuration: "1000", 9 timeOut: "2000", 10 extendedTimeOut: "
1000", 11 showEasing: "swing", 12 hideEasing: "linear", 13 showMethod: "fadeIn", 14 hideMethod: "fadeOut" 15 };

參數說明:
closeButton:false,是否顯示關閉按鈕(提示框右上角關閉按鈕);
debug:false,是否為調試;
progressBar:false,是否顯示進度條(設置關閉的超時時間進度條);
positionClass,消息框在頁面顯示的位置

1 toast-top-left  頂端左邊
2 toast-top-right    頂端右邊
3 toast-top-center  頂端中間
4 toast-top-full-width 頂端,寬度鋪滿整個屏幕
5 toast-botton-right  
6 toast-bottom-left
7 toast-bottom-center
8 toast-bottom-full-width

1 onclick,點擊消息框自定義事件 
2 showDuration: “300”,顯示動作時間 
3 hideDuration: “1000”,隱藏動作時間 
4 timeOut: “2000”,自動關閉超時時間 
5 extendedTimeOut: “10006 showEasing: “swing”, 
7 hideEasing: “linear”, 
8 showMethod: “fadeIn” 顯示的方式,和jquery相同 
9 hideMethod: “fadeOut” 隱藏的方式,和jquery相同

Jquery消息提示插件toastr使用詳解