jquery.mouseenter(function(){
$(div).animate({'margin-top':'100px'},1000)
})
jquery.mouseleave(function(){
$(div).animate({'margin-top':'200px'},1000)
})
鼠标移动到某个div上,触发mouseenter事件和动画,移出触发mouseleave事件和动画,但是来回划过这个div,事件就被触发了多次,动画也要重复好几遍,怎么才能在动画执行过程中,不触发mouseenter、mouseleave事件呢,即动画过程中,鼠标划过这个div后,动画不会重复出现,只有动画完了 ,再划过,才会触发
你可以使用stop方法:
$(div).stop(false, true).animate({'margin-top':'100px'},1000);
如果
stop()
的第一个参数为true
,表示立即清除当前的动画队列,默认为fx
;如果第二个参数为true
,表示立即将当前正在执行的动画置为它的结束状态。