Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery闪烁_Jquery_Ruby On Rails_Ruby On Rails 3 - Fatal编程技术网

jQuery闪烁

jQuery闪烁,jquery,ruby-on-rails,ruby-on-rails-3,Jquery,Ruby On Rails,Ruby On Rails 3,我有一个Rails 3应用程序,其中一个视图中包含以下内容: <li class = "comment"> ...some comment text... <ul class = "actions"> <li><a href = "#">Edit</a></li> </ul> </li> 问题是,当您将鼠标移到上时,注释鼠标上方似乎会被反复调用,从而导致操作闪烁。我尝试用mous

我有一个Rails 3应用程序,其中一个视图中包含以下内容:

<li class = "comment">
  ...some comment text...
  <ul class = "actions">
    <li><a href = "#">Edit</a></li>
  </ul>
</li>

问题是,当您将鼠标移到
上时,注释
鼠标上方似乎会被反复调用,从而导致
操作
闪烁。我尝试用
mouseenter/mouseleave
替换
mouseover/mouseout
,这在一定程度上解决了问题
.actions
在将鼠标悬停在
.comment
上时不会闪烁,但当您将鼠标悬停在
.actions
本身上方时,它会闪烁得很厉害。

您正试图在隐藏元素上添加鼠标悬停事件。如果它有一个
显示:none
$(this).hide()
),它不能被鼠标覆盖,因此也不会调用事件。我想你可能一直想这样做:

  $('.actions').hide();
   $('.comment').live('mouseover',function() {
  $(this).children('.actions').show();
}).live('mouseout',function(){
  $(this).children('.actions').hide();
}); 
例如:


如果这不是您想要的,那么问题也可能出在您的标记中,因为它被分成了许多部分,例如
a href
,或
ul class
,如果您希望在用户悬停在评论上时显示操作链接,那么我认为这更符合您的要求:

$('.comment').live('mouseover',function() {
  $(this).find('.actions').show();
}).live('mouseout',function(){
  $(this).find('.actions').hide();
});

由于事件冒泡,事件被多次调用,您要做的是:

$('.comment .actions').live('mouseover',function(e) {
  $(this).show();
  e.stopPropagation();
  e.preventDefault();
}).live('mouseout',function(e){
  $(this).hide();
  e.stopPropagation();
  e.preventDefault();
});

你在代码中缺少了几个结束引号,我想这只是因为在这里为条目设置了格式?没有结尾的引号只是我写问题时的一个输入错误。这在我的实际源代码中是正确的。不过我会试试你的解决方案。这实际上就是我的资料来源。我只是打错了。谢谢亚历克斯!这正是我要找的。过去一个小时我一直在为这件事发牢骚。@Kyle没问题,很乐意帮忙!:)
$('.comment .actions').live('mouseover',function(e) {
  $(this).show();
  e.stopPropagation();
  e.preventDefault();
}).live('mouseout',function(e){
  $(this).hide();
  e.stopPropagation();
  e.preventDefault();
});