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 通知提示插件的更多相关文章

  1. 漂亮灵活设置的jquery通知提示插件toastr

    toastr是一款非常棒的基于jquery库的非阻塞通知提示插件,toastr可设定四种通知模式:成功,出错,警告,提示,而提示窗口的位置,动画效果都可以通过能数来设置,在官方站可以通过勾选参数来生成 ...

  2. 消息提示插件toastr.js与Messenger组件

    Toastr是一款基于jQuery的通知插件,可以灵活的自定义样式和拓展其功能! toastr是一个基于Jquery简单.漂亮的消息提示插件,使用简单.方便,可以根据设置的超时时间自动消失. cdn最 ...

  3. PNotify – 简单易用的 JS 通知,消息提示插件

    PNotify 是一个 JavaScript 通知插件,前身为 Pines Notify.它旨在提供无与伦比的灵活性,同时很容易使用.它可以提供无阻塞的通知,允许用户无需关闭通知或者提示信息就可以点击 ...

  4. Jquery消息提示插件toastr使用详解

    toastr是一个基于jQuery简单.漂亮的消息提示插件,使用简单.方便,可以根据设置的超时时间自动消失. 1.使用很简单,首选引入toastr的js.css文件 html <script s ...

  5. Jquery消息提示插件toastr使用

    toastr是一个基于jQuery简单.漂亮的消息提示插件,使用简单.方便,可以根据设置的超时时间自动消失. 相关文件到官网去下载即可 1.引入toastr的js和css文件 <link hre ...

  6. Jquery消息提示插件toastr

    toastr是一个基于jQuery简单.漂亮的消息提示插件,使用简单.方便,可以根据设置的超时时间自动消失. 1.使用很简单,首选引入toastr的js.css文件 <script src=&q ...

  7. 应用 CSS3 动画实现12种风格的通知提示

    今天我们想分享几个简单的款式的网站通知效果.有很多的方式来呈现消息给用户:从经典的咆哮般的通知到窗口顶部的通知栏.各个网站的通知样式和效果千篇一律,难得出现创意的通知效果.这里是实现一个应用 CSS3 ...

  8. 使用 Swift 制作一个新闻通知中心插件(1)

    input[type="date"].form-control,.input-group-sm>input[type="date"].input-grou ...

  9. Swift 制作一个新闻通知中心插件1

    使用 Swift 制作一个新闻通知中心插件(1) 随着 iOS 8 的发布,苹果为开发者们开放了很多新的 API,而在这些开放的接口中 通知中心插件 无疑是最显眼的一个.通知中心就不用过多介绍了,相信 ...

随机推荐

  1. LeetCode 66. Plus One(加1)

    Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. Yo ...

  2. HDU 6113 度度熊的01世界

    度度熊的01世界 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  3. Can you solve this equation?

    Problem Description Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,can you find its sol ...

  4. ③bootstrap文本使用基础案例

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. Python爬虫入门:Urllib库的高级使用

    1.设置Headers 有些网站不会同意程序直接用上面的方式进行访问,如果识别有问题,那么站点根本不会响应,所以为了完全模拟浏览器的工作,我们需要设置一些Headers 的属性. 首先,打开我们的浏览 ...

  6. 让普通 Java 类自动感知 Activity Lifecycle

    背景 在 Android 开发中,我们都很熟悉 Activity 的 Lifecycle,并且会在特定的 Lifecycle 下执行特定的操作.当然,我们清楚 Lifecycle 本身是带有 Andr ...

  7. HTTPCLIENT 模拟登陆

    第一步构建忽略https验证的httpclient public static CloseableHttpClient getHttpClient() throws Exception { SSLCo ...

  8. C#中抽象类与接口的区别

    1.面向接口编程和面向对象编程是什么关系 首先,面向接口编程和面向对象编程并不是平级的,它并不是比面向对象编程更先进的一种独立的编程思想,而是附属于面向对象思想体系,属于其一部分.或者说,它是面向对象 ...

  9. 三:动态SQL

    :动态SQL 1.使用动态sql完成多条件查询 If:利用if实现简单的条件选择 Choose(when,otherwise):相当于java中的switch语句,通常与whenhe otherwis ...

  10. 基础教程:视图中的ASP.NET Core 2.0 MVC依赖注入

    问题 如何在ASP.NET Core MVC Views中注入和使用服务. 解 更新 启动 类来为MVC添加服务和中间件. 添加一项服务 添加一个Controller,返回 ViewResult. 添 ...