嗨,我想知道如何使用骨干和js处理删除悬停状态
目前我有
- events: {
- "hover .info" : "hover"
- },hover:(e) =>
- $(e.currentTarget).css("background-color","#333")
我想知道如何处理我将鼠标从元素与.info类移动的事件
如果我在标准的咖啡脚本里面做到这一点在悬停:事件处理程序,它需要2个悬停,它的工作.
我基本上想模仿
- $(".info").hover(
- function() {
- $(this).css("background-color","#333")
- },function() {
- $(this).css("background-color","#F3F")
- },});
谢谢
解决方法
有一个版本的
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:
- hover:(e) =>
- $(e.currentTarget).toggleClass('dark-gray')
默认情况下,默认的#F3F颜色将在元素上设置,您可以:
- .dark-gray {
- background-color: #333
- }
在你的样式表.如果由于某种原因无法使用toggleClass,则必须单独绑定到mouseenter和mouseleave.