2013-02-18 191 views
0

我正在写卡列表。
卡列表中的li元素既有mouseenter也有mouseleave事件。
重叠jquery鼠标悬停事件

mouseenterCard: function(index) { 
    var nOnRight = index+2; 
    var n = index+1; 

    if (n!=1) { 
     $('#cards-list li:nth-child('+n.toString()+')').animate({'margin-left': '30px'}, 
                   "fast", 
                   function() { 

                   }); 
    } 
    $('#cards-list li:nth-child('+nOnRight.toString()+')').animate({'margin-left': '30px'}, 
                    "fast"); 
}, 
mouseleaveCard: function(index) { 
    var nOnRight = index+2; 
    var n = index+1; 
    if (n!=1) { 
     $('#cards-list li:nth-child('+n.toString()+')').animate({'margin-left': marginLeft.toString()+'px'}, 
                   "fast", 
                   function() { 

                   }); 
    } 
    $('#cards-list li:nth-child('+nOnRight.toString()+')').animate({'margin-left': marginLeft.toString()+'px'}, 
                    "fast"); 
} 

$('#cards-list').on('mouseenter', 'li' ,function(e){ 
    CardList.getInstance().mouseenterCard($(this).index()); 
}); 

$('#cards-list').on('mouseleave', 'li' ,function(e){ 
    CardList.getInstance().mouseleaveCard($(this).index()); 
}); 

这里是DEMO
正如你两个元素之间交换快,li元素的行为怪异。
问题是什么?

回答

0

多次移动相同元素时,动画会排队。您有一定.stop.finish停止动画(后者结束动画即时):

$('#cards-list li:nth-child('+nOnRight.toString()+')').stop().animate(...