Javascript Toastr JS 设置淡入淡出值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14631844/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 17:25:55  来源:igfitidea点击:

Toastr JS Setting fadeAway value

javascriptalerttoastr

提问by Ravi Ram

I am using a cool alert js library Project: https://github.com/CodeSeven/toastr

我正在使用一个很酷的警报 js 库项目:https: //github.com/CodeSeven/toastr

I wanted to fadeOut the following alter after a period of time. Looking at the toastr.js file, I do see the options are there. I just dont know how to access the property 'fadeAway'

我想在一段时间后淡出以下更改。查看 toastr.js 文件,我确实看到了选项。我只是不知道如何访问属性“fadeAway”

toastr.info('Processing...');

I tried

我试过

toastr.info('Processing...', fadeAway:1000);

How do I use the fadeAway by passing in a parameter ?

如何通过传入参数来使用fadeAway?

回答by John Papa

Before you call toastr.info, set the option you choose. For example:

在调用 toastr.info 之前,设置您选择的选项。例如:

toastr.options.fadeOut = 2500;

You can see many of the options in the demo here: toastr demo

您可以在此处查看演示中的许多选项:toastr demo

These are the defaults. You can override many of them:

这些是默认值。您可以覆盖其中许多:

options = {
  tapToDismiss: true,
  toastClass: 'toast',
  containerId: 'toast-container',
  debug: false,
  fadeIn: 300,
  fadeOut: 1000,
  extendedTimeOut: 1000,
  iconClass: 'toast-info',
  positionClass: 'toast-top-right',
  timeOut: 5000, // Set timeOut to 0 to make it sticky
  titleClass: 'toast-title',
  messageClass: 'toast-message'
}

回答by Brian Ogden

With version 2.0.3 you do the following to make the toastr display longer:

在 2.0.3 版本中,您可以执行以下操作来延长 toastr 的显示时间:

toastr.success('Hello World', 'New Message', { timeOut: 9500 });

回答by Marius St?nescu

You can also pass any options in a parameter. But the parameter must be an object. For your example you can use this:

您还可以在参数中传递任何选项。但是参数必须是一个对象。对于您的示例,您可以使用它:

toastr.info('Processing...', { fadeAway: 1000 });

PS: also keep in mind that fadeAway is deprecated in the current version (2.0.3).

PS:还要记住,fadeAway 在当前版本 (2.0.3) 中已被弃用。