toastr 通知提示插件
jquery toastr 一款轻量级的通知提示框插件。
网页开发中经常会用到提示框,自带的alert样式无法调整,用户体验差。
所以一般通过自定义提示框来实现弹窗提示信息,而jquery toastr正是为此的一款非常棒的插件。
开发中用angular比较多,所以笔记记录了angular一些常见使用,与jquery版本有些许不同 ,相差不大。
在HTML引用js文件
<link rel="stylesheet" type="text/css" href="angular-toastr.css" />
<script type="text/javascript" src="angular-toastr.tpls.js"></script>
在angular模版中注入依赖
angular.module('app', ['ngAnimate', 'toastr'])
toastr使用中会用到动画,所以需加上ngAnimate,如果不引入ngAnimate,没有动画效果,不影响显示。
开始使用
1.成功提示
toastr.success('Hello world!', 'Toastr fun!');

2.普通提示
toastr.info('We are open today from 10 to 22', 'Information');

3.错误提示
toastr.error('Your credentials are gone', 'Error');

4.警告提示
toastr.warning('Your computer is about to explode!', 'Warning');

第一个参数为提示内容,第二个参数为提示标题,如果不需要标题,则可省略第二个参数
toastr.success('I don\'t need a title to live');

关闭提示框
toastr.clear([toast]);
获取当前显示的提示框
toastr.active();
刷新打开的提示框(第二个参数配置超时时间)
toastr.refreshTimer(toast, 5000);
全局配置
app.config(function(toastrConfig) {
angular.extend(toastrConfig, {
autoDismiss: false,
containerId: 'toast-container',
maxOpened: 0,
newestOnTop: true,
positionClass: 'toast-top-right',
preventDuplicates: false,
preventOpenDuplicates: false,
target: 'body'
});
});
- autoDismiss: true 显示最新的toastr
- containerId: 默认为"toast-container",设置toastr容器的id名称.
- maxOpened: 页面一次性最多显示多少个toastr.
- newestOnTop: true 新的toastr会显示在旧的toastr前面
- positionClass: 设置toastr显示位置的class
- preventDuplicates: true 重复内容的提示框只出现一次,无论提示框是打开还是关闭
- preventOpenDuplicates: true 重复内容的提示框在开启时只出现一个 如果当前的提示框已经打开,不会多开。直到提示框关闭后,才可再开)
- target: 默认为'body', 设置toastr的目标容器
| positionClass | |
|---|---|
| toast-top-left | 顶端左边 |
| toast-top-right | 顶端右边 |
| toast-top-center | 顶端中间 |
| toast-top-full-width | 顶端中间(宽度铺满) |
| toast-bottom-right | 底部右边 |
| toast-bottom-left | 底部左边 |
| toast-bottom-center | 底部中间 |
| toast-bottom-full-width | 底部中间(宽度铺满) |
app.config(function(toastrConfig) {
angular.extend(toastrConfig, {
allowHtml: false,
closeButton: false,
closeHtml: '<button>×</button>',
extendedTimeOut: 1000,
iconClasses: {
error: 'toast-error',
info: 'toast-info',
success: 'toast-success',
warning: 'toast-warning'
},
messageClass: 'toast-message',
onHidden: null,
onShown: null,
onTap: null,
progressBar: false,
tapToDismiss: true,
templates: {
toast: 'directives/toast/toast.html',
progressbar: 'directives/progressbar/progressbar.html'
},
timeOut: 5000,
titleClass: 'toast-title',
toastClass: 'toast'
});
});
- allowHtml: 设置提示内容可包含html格式
- closeButton: 设置显示"X" 关闭按钮
- closeHtml: 自定义html替代closeButton内容,closeButton为true时才显示.
- extendedTimeOut: 设置当你鼠标滑入后的timeout,该timeout会更新关闭所需的timeout.
- extraData: 如果重写模版,你可以自定义全局数据给你的toasts
- iconClasses: 设置各个类型的icon图标class
- messageClass: 设置toastr提示信息的class
- progressBar: 设置显示timeout时间进度条
- tapToDismiss: 设置toastr被点击时关闭
- templates: 自定义模版
- timeOut: 设置toastr过多久关闭
- titleClass: 设置toastr标题的class
- toastClass: 设置toastr基本的class
参考文章:
jquery: https://github.com/CodeSeven/toastr
angular: https://github.com/Foxandxss/angular-toastr
toastr 通知提示插件的更多相关文章
- 漂亮灵活设置的jquery通知提示插件toastr
toastr是一款非常棒的基于jquery库的非阻塞通知提示插件,toastr可设定四种通知模式:成功,出错,警告,提示,而提示窗口的位置,动画效果都可以通过能数来设置,在官方站可以通过勾选参数来生成 ...
- 消息提示插件toastr.js与Messenger组件
Toastr是一款基于jQuery的通知插件,可以灵活的自定义样式和拓展其功能! toastr是一个基于Jquery简单.漂亮的消息提示插件,使用简单.方便,可以根据设置的超时时间自动消失. cdn最 ...
- PNotify – 简单易用的 JS 通知,消息提示插件
PNotify 是一个 JavaScript 通知插件,前身为 Pines Notify.它旨在提供无与伦比的灵活性,同时很容易使用.它可以提供无阻塞的通知,允许用户无需关闭通知或者提示信息就可以点击 ...
- Jquery消息提示插件toastr使用详解
toastr是一个基于jQuery简单.漂亮的消息提示插件,使用简单.方便,可以根据设置的超时时间自动消失. 1.使用很简单,首选引入toastr的js.css文件 html <script s ...
- Jquery消息提示插件toastr使用
toastr是一个基于jQuery简单.漂亮的消息提示插件,使用简单.方便,可以根据设置的超时时间自动消失. 相关文件到官网去下载即可 1.引入toastr的js和css文件 <link hre ...
- Jquery消息提示插件toastr
toastr是一个基于jQuery简单.漂亮的消息提示插件,使用简单.方便,可以根据设置的超时时间自动消失. 1.使用很简单,首选引入toastr的js.css文件 <script src=&q ...
- 应用 CSS3 动画实现12种风格的通知提示
今天我们想分享几个简单的款式的网站通知效果.有很多的方式来呈现消息给用户:从经典的咆哮般的通知到窗口顶部的通知栏.各个网站的通知样式和效果千篇一律,难得出现创意的通知效果.这里是实现一个应用 CSS3 ...
- 使用 Swift 制作一个新闻通知中心插件(1)
input[type="date"].form-control,.input-group-sm>input[type="date"].input-grou ...
- Swift 制作一个新闻通知中心插件1
使用 Swift 制作一个新闻通知中心插件(1) 随着 iOS 8 的发布,苹果为开发者们开放了很多新的 API,而在这些开放的接口中 通知中心插件 无疑是最显眼的一个.通知中心就不用过多介绍了,相信 ...
随机推荐
- Mongodb的mongostat命令
Mongodb的mongostat命令可实时(1秒钟刷新一次)显示Mongodb数据库的运行情况,可视为性能监视器. 1.启动命令:authenticationDatabase表示用户认证证书所在的数 ...
- 关于echarts、layer.js和jqGrid的知识点
使用echarts和layer.js直接去官方文档,能解决大部分问题. 但是有些问题,解释不够清楚,在这里记录一下. 1.echarts的使用 第一点:关于echarts的labelline在数据为零 ...
- Android O --Soong Build
Concept: Kati (https://android.googlesource.com/platform/build/kati/) - Reads Android.mk files -> ...
- Java基础笔记9
super关键字 表示父类对象. 1.可以调用父类中被重写的方法. 2.还有调用父类中的构造方法.放在子类构造方法的第一行. 不能和this关键字同时出现. final关键字 1.修饰属性.表示常量. ...
- 2015ACM/ICPC亚洲区沈阳站 Pagodas
Pagodas Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- shell编程下 特殊变量、test / [ ]判断、循环、脚本排错
第1章 shell中的特殊变量 1.1 $# $# 表示参数的个数 1.1.1 [示例]脚本内容 [root@znix ~]# cat /server/scripts/show2.sh #!/bin/ ...
- git使用教程之git基础
1 获取Git仓库 在现有目录中初始化仓库 git init 克隆现有的仓库 git clone https://github.com/yangwang12345/node_test.git Git ...
- javascript 可多选的下拉框 multiselect
首先引用一个写的很好的博客http://www.cnblogs.com/landeanfen/p/5013452.html 我使用的是bootstrap-multiselect,实现功能是 选择下拉框 ...
- margin负值的相关应用
1.页面上实现css sprite背景定位效果 其实margin:-40px 0 0 -160px;与background-position:-160px -40px;实现的原理是一致的,而差别就 ...
- 算法:JavaScript两数之和
题目 Given an array of integers, return indices of the two numbers such that they add up to a specific ...