【发布时间】:2012-05-26 19:50:49
【问题描述】:
我的函数是触发第二个mouseleave() 事件而不是第一个事件,导致nth-child(1) 和nth-child(2) 在我希望他们使用第一个mouseleave() 事件时具有bottom:99px 的.css 属性将属性设置为bottom:94px
经过一些研究,我相当确定我需要关闭我的 (this) 语句,以便当我在第二轮参数中调用它时,它可以在新范围内工作..?
$(document).ready(function(){
$('#rows').on('mouseenter', "div.row div:nth-child(1), div.row div:nth-child(2)",this , function() {
$('img',this).stop().animate({"bottom":"0px"}, "fast");
});
$('div',this).off("mouseleave").on("mouseleave", function() {
$('img',this).stop().animate({"bottom":"94px"}, "fast");
});
// need closure here?
$('#rows').on('mouseenter', "div.row div:nth-child(3), div.row div:nth-child(4)",this , function() {
$('img',this).stop().animate({"bottom":"0px"}, "fast");
});
$('div',this).off("mouseleave").on("mouseleave", function() {
$('img',this).stop().animate({"bottom":"99px"}, "fast");
});
});
【问题讨论】:
标签: jquery closures this mouseenter mouseleave