【问题标题】:clearTimeout not working for popover variable undefinedclearTimeout 不适用于未定义的弹出框变量
【发布时间】:2012-09-17 08:46:54
【问题描述】:

好的,所以我在 users.js.coffee 中有一些咖啡脚本,它在滚动用户名时运行 twitter 引导弹出窗口(目前正在工作)现在我想要做的是使用超时来隐藏弹出窗口,如果用户没有将鼠标悬停在弹出框上。

这是我的代码(当前抛出 Uncaught ReferenceError: timeoutObj is not defined on scrollover of the popover)我的问题显然出在 timeoutObj 变量上,尽管它应该在 mouseleave 方法中设置?

$ ->
 timeoutObj = undefined
 $(".comment-user-name").popover({
   trigger: "manual"
   placement: 'top'
   template: '<div class="popover" onmouseover="clearTimeout(timeoutObj);$(this).mouseleave(function() {$(this).hide(); });"><div class="arrow"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content"><p></p></div></div></div>'
 })
 $(".comment-user-name").mouseenter((event, ui) ->
   $(".comment-user-name").popover('show') 
 )
 $(".comment-user-name").mouseleave((event, ui) ->
   timeoutObj = setTimeout (-> $(".comment-user-name").popover('hide') ), 3000
 )

【问题讨论】:

    标签: javascript twitter-bootstrap timeout coffeescript popover


    【解决方案1】:

    这是正确的代码:

    $ ->
          timeoutObj = null
          $(".comment-user-name").popover(
              {
              trigger  : "manual"
              placement: 'top'
              template : '<div class="popover"><div class="arrow"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content"><p></p></div></div></div>'
              }
          )
    
          $(".popover").onmouseover(
              (event, ui) ->
                  clearTimeout(timeoutObj)
                  $(this).mouseleave(-> $(this).hide())
          )
          $(".comment-user-name").mouseenter((event, ui) -> $(".comment-user-name").popover('show'))
          $(".comment-user-name").mouseleave((event, ui) -> timeoutObj = setTimeout (-> $(".comment-user-name").popover('hide') ), 3000)
    

    '&lt;div class="popover" onmouseover="...中不能使用 timeoutObj

    【讨论】:

    • 感谢我正在寻找的东西。
    猜你喜欢
    • 2018-09-10
    • 2013-06-11
    • 2021-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-02
    相关资源
    最近更新 更多