基本上我mouseleave
在单击元素后取消绑定。但是我希望在单击另一个元素时mouseleave
让该元素的 -event 再次工作。我的代码可以运行,但感觉很笨重,因为我在代码中不断地重复动画。
mouseleave
除了解除绑定和“重新绑定”之外,没有其他方法可以暂时抑制这种情况吗?有什么建议么 ?
HTML
<div class="container">
CONTAINER ONE
</div>
<div class="container">
CONTAINER TWO
</div>
JS:
$(document).ready(function()
{
//the default hover-event
$('.container').hover(
function(){
$(this).stop().animate({'padding-bottom':'10px'},{queue:false,duration:160});
},
function() {
$(this).stop().animate({'padding-bottom':'0px'},{queue:false,duration:160});
}
);
$('.container').click(function(e) {
e.preventDefault();
// enables the mouseleave for all other `.container`s again.
// also bring the old clicked element into unhovered position again
$('.container')
.bind('mouseleave',function() {
$(this).stop().animate({'padding-bottom':'0px'},{queue:false,duration:160});
}).not(this).stop().animate({'padding-bottom':'0px'},{queue:false,duration:160});
// supress the mouseleave for the clicked element
$(this).unbind('mouseleave');
})
});