toastr弹出自动消失提示框

本文介绍如何使用toastr.js库创建非阻塞的自动消失消息提示框,包括快速启动步骤、自定义参数设置及示例代码,帮助前端开发者提升用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • 情景描述

当我们前端进行一些操作后,不管失败还是成功,都需要由信息来提示用户的操作结果,给出明确的信息和友好提示,对于自动消失的消息提示框的需要就产生了。

  • 思路

    toastr:https://www.bootcdn.cn/toastr.js/

    这是一个基于Jquery的库,可以通过引入js和css来达到很友好的提示框效果。

 Quick start

 3 Easy Steps

For other API calls, see the demo.

  1. Link to toastr.css <link href="toastr.css" rel="stylesheet"/>

  2. Link to toastr.js <script src="toastr.js"></script>

  3. use toastr to display a toast for info, success, warning or error

    // Display an info toast with no title
    toastr.info('Are you the 6 fingered man?')
  • 自定义用法

通过设置自定义参数,可达到不同的效果

自定义参数: 
javascript

toastr.options = {  
        closeButton: false,  
        debug: false,  
        progressBar: true,  
        positionClass: "toast-bottom-center",  
        onclick: null,  
        showDuration: "300",  
        hideDuration: "1000",  
        timeOut: "2000",  
        extendedTimeOut: "1000",  
        showEasing: "swing",  
        hideEasing: "linear",  
        showMethod: "fadeIn",  
        hideMethod: "fadeOut"  
    };  

参数说明: 
closeButton:false,是否显示关闭按钮(提示框右上角关闭按钮); 
debug:false,是否为调试; 
progressBar:false,是否显示进度条(设置关闭的超时时间进度条); 
positionClass,消息框在页面显示的位置

toast-top-left  顶端左边
toast-top-right    顶端右边
toast-top-center  顶端中间
toast-top-full-width 顶端,宽度铺满整个屏幕
toast-botton-right  
toast-bottom-left
toast-bottom-center
toast-bottom-full-width

onclick,点击消息框自定义事件 
showDuration: “300”,显示动作时间 
hideDuration: “1000”,隐藏动作时间 
timeOut: “2000”,自动关闭超时时间 
extendedTimeOut: “1000” 
showEasing: “swing”, 
hideEasing: “linear”, 
showMethod: “fadeIn” 显示的方式,和jquery相同 
hideMethod: “fadeOut” 隐藏的方式,和jquery相同
--------------------- 
版权声明:本文为优快云博主「风中斗士」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.youkuaiyun.com/cyh1111/article/details/53141037/

  • 阻塞与非阻塞提示框

    toastr其实是非阻塞提示框,所以,如果后续有其他操作,那么就有可能出现弹框还来不及弹出的情况,而alert是阻塞提示框,需要手动确认后才会继续进行后续操作。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值