2012-07-03 78 views
0

下面的代码应该可以防止弹出窗口关闭,如果您将鼠标悬停在该按钮上或该按钮上,但是它只能在重新加载时才起作用,然后停止工作。代码只执行一次,但应该继续

$('.popover3-test').popover({ 
    placement:'bottom', 
    template: $('.popover2'), 
    trigger: 'manual', 

    }).mouseenter(function(e) { 
    $(this).popover('show'); 

    var t = null; 

    $(".popover2, .popover3-test") 
     .mouseleave(function() { 
      t = setTimeout(function() { 
       $('.popover2').hide(); 
      }, 1000); // Or however many milliseconds 
     }) 
     .mouseenter(function() { 
      if(t !== null) 
       clearTimeout(t); 
     }); 
    }); 

演示:http://jsfiddle.net/MnpWV/1/

+0

请更改您的问题 – Ibu

+0

它工作一次,然后停止工作,我希望它继续工作。 – dezman

+1

@watson删除'clearTimeout'然后它将工作。 http://jsfiddle.net/MnpWV/2/ – undefined

回答

1

试试这个:

$(".popover2, .popover3-test") 
     .mouseleave(function() { 
      $('.popover2').delay(1000).fadeOut('1000'); 
     } 
}); 

http://jsfiddle.net/MnpWV/8/

更新:

$(".popover2").hover(function(e) { 
    $(this).show() 
}, function() { 
    $('this').delay(1000).fadeOut('1000'); 
}) 

http://jsfiddle.net/MnpWV/16/

删除触发mouseleave事件的.popover3-test

+0

如果您将鼠标悬停在弹出窗口('.popover2')上,它应该保持可见。 – dezman

+0

现在,如果您从未将鼠标悬停在.popover2上,它永远不会消失。 – dezman

+0

shucks,但是谢谢 – dezman