javascript - jQuery + CSS : How to detect the first "move out" of cursor out of an element?

标签 javascript jquery html css

我正在尝试做与 Twitter 相同的事情——当您单击“关注”按钮时,系统会在其中添加一个名为 cancel-hover-style 的类。当您将光标移出此按钮时,CSS 类 cancel-hover-style 将被删除。

如何检测这个“先出”?

谢谢

最佳答案

不要使用on/off。 jQuery 有一个内置的解决方案。

使用jQuery.one .它只会执行一次处理程序。

您可以使用它来监听第一个(且仅是第一个)mouseout 事件,并删除您有兴趣删除的任何 CSS 类。

elem.one("mouseout",  function() { $(this).removeClass("hoverClass"); })

关于javascript - jQuery + CSS : How to detect the first "move out" of cursor out of an element?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24660362/

相关文章:

html - 具有可变列号的响应表

javascript - 将输入框 2 的文本更改为输入框 1 Angular 2 中的更改?

javascript - 用 JavaScript 替换类名

php - MYSQL根据jquery可排序的特定顺序进行更新

javascript - 如何创建具有我自己风格的所见即所得编辑器?

javascript - 如何按名称过滤元素

javascript - jQuery 检查 CSS 颜色值不工作

javascript - Sequelize : Eager Loading and Ordering (on parent table)

jQuery 数据表 : Filter per column

java - XML 解析错误 : no element found Location: moz-nullprincipal (not strong with ajax)