jquery – 骨干事件

前端之家收集整理的这篇文章主要介绍了jquery – 骨干事件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
嗨,我想知道如何使用骨干和js处理删除悬停状态

目前我有

  1. events: {
  2. "hover .info" : "hover"
  3. },hover:(e) =>
  4. $(e.currentTarget).css("background-color","#333")

我想知道如何处理我将鼠标从元素与.info类移动的事件

如果我在标准的咖啡脚本里面做到这一点在悬停:事件处理程序,它需要2个悬停,它的工作.

我基本上想模仿

  1. $(".info").hover(
  2. function() {
  3. $(this).css("background-color","#333")
  4. },function() {
  5. $(this).css("background-color","#F3F")
  6. },});

谢谢

解决方法

有一个版本的 hover() that takes one callback function

Description: Bind a single handler to the matched elements,to be executed when the mouse pointer enters or leaves the elements.

这是由Backbone使用的悬停版本.所以你可以使用toggleClass和几个CSS类来处理这个问题,而不是直接搞砸css:

  1. hover:(e) =>
  2. $(e.currentTarget).toggleClass('dark-gray')

默认情况下,默认的#F3F颜色将在元素上设置,您可以:

  1. .dark-gray {
  2. background-color: #333
  3. }

在你的样式表.如果由于某种原因无法使用toggleClass,则必须单独绑定到mouseenter和mouseleave.

猜你在找的jQuery相关文章