cof*_*ime 13 css jquery coffeescript backbone.js
嗨,我想知道如何使用backbone和js处理删除悬停状态
目前我有
events: {
"hover .info" : "hover"
},
hover:(e) =>
$(e.currentTarget).css("background-color", "#333")
Run Code Online (Sandbox Code Playgroud)
我想知道如何处理事件,我将鼠标从类.info上移开元素
如果我在hover:event处理程序里面做标准咖啡脚本,它需要2个鼠标悬停才能工作.
我基本上想模仿
$(".info").hover(
function() {
$(this).css("background-color", "#333")
},
function() {
$(this).css("background-color", "#F3F")
},
});
Run Code Online (Sandbox Code Playgroud)
谢谢
nra*_*itz 27
来自jQuery文档:
通话
$(selector).hover(handlerIn, handlerOut)
是简写:
$(selector).mouseenter(handlerIn).mouseleave(handlerOut);
因此我认为使用Backbone处理此问题的最佳方法就是设置两个事件(抱歉,我不相信CoffeeScript):
events: {
"mouseenter .info" : "hoverOn",
"mouseleave .info" : "hoverOff"
},
hoverOn: function(e) { ... },
hoverOff: function(e) { ... }
Run Code Online (Sandbox Code Playgroud)
或者,你可以使用单个参数语法,它接受一个函数并在内外调用它 - 这适用于.toggle()
和toggleClass()
.
mu *_*ort 22
有一个版本hover()
需要一个回调函数:
描述:将单个处理程序绑定到匹配的元素,以便在鼠标指针进入或离开元素时执行.
这是hover
Backbone将使用的版本.所以你可以使用toggleClass
和几个CSS类来处理这个,而不是直接搞乱css
:
hover:(e) =>
$(e.currentTarget).toggleClass('dark-gray')
Run Code Online (Sandbox Code Playgroud)
默认情况下,默认#F3F
颜色将在元素上设置,您将拥有:
.dark-gray {
background-color: #333
}
Run Code Online (Sandbox Code Playgroud)
在你的样式表中.如果你因为某些原因使用toggleClass
,你必须结合mouseenter
和mouseleave
个别.
归档时间: |
|
查看次数: |
17873 次 |
最近记录: |