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');
})
});