正常的鼠标离开功能可以正常工作,但是如果我们离开鼠标的速度非常慢,那么鼠标退出功能就无法正常工作..
var timeoutId;
$('.box').mouseover(function(){
var $this=$(this);
if (!timeoutId) {
timeoutId = window.setTimeout(function() {
timeoutId = null;
$this.animate({
marginTop:'-224px',
height:'300px'
})
$this.find('.rotate-arrow').addClass('rotate');
$this.find('.header-content-span').css('display','none');
},1000); }
});
$('.box').mouseleave(function(){
var $this=$(this);
if (timeoutId) {
window.clearTimeout(timeoutId);
timeoutId = null;
$this.animate({
marginTop:'0px',
height:'77px'
})
$this.find('.rotate-arrow').removeClass('rotate');
$this.find('.header-content-span').css('display','block');
}