标签:ogre rip hello head inf height tle 调整 enter
jquery toastr 一款轻量级的通知提示框插件。
网页开发中经常会用到提示框,自带的alert样式无法调整,用户体验差。
所以一般通过自定义提示框来实现弹窗提示信息,而jquery toastr正是为此的一款非常棒的插件。
开发中用angular比较多,所以笔记记录了angular一些常见使用,与jquery版本有些许不同 ,相差不大。
<link rel="stylesheet" type="text/css" href="angular-toastr.css" /> <script type="text/javascript" src="angular-toastr.tpls.js"></script>
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‘
});
});
| 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‘
});
});
参考文章:
jquery: https://github.com/CodeSeven/toastr
angular: https://github.com/Foxandxss/angular-toastr
标签:ogre rip hello head inf height tle 调整 enter
原文地址:http://www.cnblogs.com/kenz520/p/6964904.html