【问题标题】:Auto Dismiss Bootstrap Alert stopped working in Rails自动关闭引导警报停止在 Rails 中工作
【发布时间】:2015-02-22 17:24:28
【问题描述】:

我在我的 Ruby on Rails 应用程序中使用以下代码自动关闭成功警报:

$ ->
  flashCallback = ->
    $(".alert-success").fadeOut()
  $(".alert-success").bind 'click', (ev) =>
    $(".alert-success").fadeOut()
  setTimeout flashCallback, 3000

与相关的警告行:

<div class="alert alert-<%= name.to_s == "notice" ? "success" : "danger" %> alert-dismissable">

一切都很好,但它似乎在途中的某个地方坏了。

我的所有代码都可以在这里找到:https://github.com/vroomanj/updemo

有没有更好的方法来完成我想要完成的事情?有没有人认为我正在做的事情有什么问题可能导致它停止工作?我希望我能说它什么时候停止工作,但我现在才注意到。

【问题讨论】:

    标签: javascript ruby-on-rails ruby twitter-bootstrap coffeescript


    【解决方案1】:

    使用通知http://ned.im/noty/#/about

    我是这样用的

    将此代码添加到 application.js.coffee

    window.show_notification = (text, type)->
      n = noty({
        layout: 'topRight'
        text: text
        type: type
        theme: 'relax'
        animation:
          open: "animated bounceInRight"
          close: "animated fadeOut"
      })
      setTimeout (->
          n.close()
        ), 5000
    

    我的 Flash 消息部分采用纤薄格式

    javascript:
      if(#{flash[:notice].present?}){
        show_notification("<span class= 'fa fa-check-circle'></span> #{flash[:notice]}", 'success')
      }
    
      if(#{flash[:alert].present?}){
        show_notification("<span class= 'fa fa-exclamation-circle '></span> #{flash[:alert]}", 'error')
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-30
      • 2014-12-12
      • 2016-04-13
      • 2018-11-27
      • 2018-10-26
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      相关资源
      最近更新 更多