【问题标题】:toastr: show after n seconds on pageloadtoastr:在页面加载 n 秒后显示
【发布时间】:2017-08-08 06:31:38
【问题描述】:

我不知道如何在页面加载 5 秒后显示 toastr。

JS:

 $(function () {
 // Toastr options
 toastr.options = {
    "debug": false,
    "newestOnTop": false,
    "positionClass": "toast-top-center",
    "closeButton": true,
    "toastClass": "animated  fadeInDown",
     };
     setTimeout(function (){
    $('.homerDemo2')(function (){
    toastr.success('Success - This is a Homer success notification');
    }, 3000)
   });
   });

【问题讨论】:

  • 很确定您的代码中存在语法错误。请正确缩进并确保您尝试执行的代码格式正确。
  • $('.homerDemo2')(function (){ 是什么意思?这永远不会被执行。只需输入setTimeout(function () { toastr.success('Success - This is a Homer success notification'); }, 3000);

标签: javascript css toastr


【解决方案1】:

我认为您混淆了脚本末尾的右括号。 使用一致的编码风格显示你的括号应该放在哪里:

$(function () {
   // Toastr options
   toastr.options = {
      "debug": false,
      "newestOnTop": false,
      "positionClass": "toast-top-   center",
      "closeButton": true,
      "toastClass": "animated  fadeInDown",
   };

   setTimeout(function () {
      $('.homerDemo2')(function () {
         toastr.success('Success - This is a Homer success notification');
      });

   }, 3000);
});

编辑setTimeout 以毫秒为单位设置超时。因此,如果您希望在 5 秒后显示它(在您的示例中不是 3),请将超时设置为 5000

【讨论】:

  • 谢谢,我稍后试试!谢谢,我知道时差 3/5 秒。
  • 嗨,不幸的是,它不起作用,烤面包机没有出现。
【解决方案2】:

用 toastr 找到解决方案,你基本上定义了 onclick=null。

$(function () {
    // Toastr options
    toastr.options = {
        "closeButton": true,
        "debug": false,
        "newestOnTop": false,
        "progressBar": false,
        "positionClass": "toast-top-right",
        "preventDuplicates": false,
        "onclick": null,
        "showDuration": "3000",
        "hideDuration": "10000",
        "timeOut": "200000",
        "extendedTimeOut": "100000",
        "showEasing": "swing",
        "hideEasing": "linear",
        "showMethod": "fadeIn",
        "hideMethod": "fadeOut"
    }
    toastr.success("foo");

});

【讨论】:

    猜你喜欢
    • 2016-03-18
    • 1970-01-01
    • 2017-04-02
    • 1970-01-01
    • 1970-01-01
    • 2018-11-08
    • 1970-01-01
    • 1970-01-01
    • 2022-01-09
    相关资源
    最近更新 更多