【问题标题】:jquery mouseover / mouseout problemjquery mouseover / mouseout 问题
【发布时间】:2009-11-02 04:39:54
【问题描述】:

我有一个包含元素列表(项目)的页面 - 这些元素是动态绘制的,因此是 live。当用户滚动项目时,我希望他们切换到“打开”的类,然后当他们滚下(鼠标移出)时,项目恢复正常。这些项目使用下面的代码行打开,但不要关闭。有什么建议吗?

$('.item').live('mouseover', function(){$(this).switchClass('item','item_on', 500);});
$('.item_on').live('mouseout', function(){$(this).switchClass('item_on','item', 500);});

谢谢!

【问题讨论】:

    标签: jquery mouseover mouseout


    【解决方案1】:
    $('.item').live('mouseover',
    function(){$(this).addClass('item_on');});
    $('.item').live('mouseout',
    function(){$(this).removeClass('item_on');});
    

    另外,我认为要使 switchClass 工作,您需要在 jquery 之后包含 jQuery UI,但在您的脚本之前,可能发生的情况是鼠标在 .item_on 元素创建之前离开 .item 元素延迟。

    另外,我认为您正在寻找的不是可能不会触发实时事件处理程序的延迟开关类,而是尝试使用 http://cherne.net/brian/resources/jquery.hoverIntent.html 与上述 addClass / removeClass。

    【讨论】:

      猜你喜欢
      • 2021-12-20
      • 2010-10-25
      • 1970-01-01
      • 1970-01-01
      • 2011-03-03
      • 1970-01-01
      • 2012-04-24
      • 2013-02-11
      • 1970-01-01
      相关资源
      最近更新 更多