Toastr 通知提示插件

Toastr 简介

jquery toastr 一款轻量级的通知提示框插件。

网页开发中经常会用到提示框,自带的alert样式无法调整,用户体验差。

所以一般通过自定义提示框来实现弹窗提示信息,而jquery toastr正是为此的一款非常棒的插件。

 

开发中用angular比较多,所以笔记记录了angular一些常见使用,与jquery版本有些许不同 ,相差不大。

在HTML引用js文件

<link rel="stylesheet" type="text/css" href="./static/toastr/toastr.min.css">
<script src="./static/toastr/toastr.min.js"></script>

 注意:导入toastr.min.js文件欠必须要先导入jQuery原生文件

在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);

  

全局配置

<script type="text/javascript">
 toastr.options = {
        closeButton: false,
        debug: false,
        progressBar: false,
        positionClass: "toast-top-center",
        onclick: null,
        showDuration: "300",
        hideDuration: "1000",
        timeOut: "5000",
        extendedTimeOut: "1000",
        showEasing: "swing",
        hideEasing: "linear",
        showMethod: "fadeIn",
        hideMethod: "fadeOut"
    };
</script>
参数名称说明可选项
closeButton是否显示关闭按钮true,false
debug是否使用debug模式true,false
positionClass弹出窗的位置具体见下文
showDuration显示的动画时间 
hideDuration消失的动画时间 
timeOut展现时间 
extendedTimeOut加长展示时间 
showEasing显示时的动画缓冲方式swing
hideEasing消失时的动画缓冲方式linear
showMethod显示时的动画方式fadeIn
hideMethod消失时的动画方式fadeOut

 

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底部中间(宽度铺满)

 

参考文章:

jquery:  https://github.com/CodeSeven/toastr

angular: https://github.com/Foxandxss/angular-toastr

 

 
 
 

转载于:https://www.cnblogs.com/fu-yong/p/8609597.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值