Ich habe ein Ereignis, das angezeigt und ausgeblendet wird, wenn die Maus mehrmals darüber bewegt wird. Wie kann ich das Ereignis sofort nach der Ausführung des Maus-Aus-Ereignisses stoppen?
$(".target").on('mouseenter',function() {
$(this).children('.p1').show(function(){
$(this).addClass('animated fadeInLeft');
$(this).removeClass('animated fadeInLeft');
})
});
$(".target").on('mouseleave',function() {
$(this).children('.p1').hide(function(){
$(this).addClass('animated fadeOutLeft');
$(this).removeClass('animated fadeOutLeft');
})
});
ringa_lee
題主如果要用只執(zhí)行一次的方法,用.one()
就行,但是一般jQuery的動畫特效一定要考慮動畫隊列的問題,建議在執(zhí)行動畫之前加上.stop()
方法來停止“進入動畫隊列但是未完全執(zhí)行完”的動畫
$(".target").on('mouseenter',function() {
$(this).children('.p1').show(function(){
$(this).addClass('animated fadeInLeft');
$(this).removeClass('animated fadeInLeft');
})
});
$(".target").on('mouseleave',function() {
$(this).children('.p1').hide(function(){
$(this).addClass('animated fadeOutLeft');
$(this).removeClass('animated fadeOutLeft');
})
$(this).unbind(); //加一句這個取消當前dom的所有綁定事件
});
$(".target").off('mouseenter').on('mouseenter',function() {
$(this).children('.p1').show(function(){
$(this).addClass('animated fadeInLeft');
$(this).removeClass('animated fadeInLeft');
})
});
$(".target").off('mouseenter').on('mouseleave',function() {
$(this).children('.p1').hide(function(){
$(this).addClass('animated fadeOutLeft');
$(this).removeClass('animated fadeOutLeft');
})
});