Javascript jQuery-悬停时淡入淡出的动画
我有一个小的jQuery动画,当鼠标悬停在一个Javascript jQuery-悬停时淡入淡出的动画,javascript,jquery,animation,effect,Javascript,Jquery,Animation,Effect,我有一个小的jQuery动画,当鼠标悬停在一个 $(function() { $('.delete').hide(); $('#photos img').hover(function() { $(this).parents('li').children('.delete').fadeIn('fast'); }, function() { $(this).parents('li').children('.delete').fadeOut('fast'); }); }
$(function() {
$('.delete').hide();
$('#photos img').hover(function() {
$(this).parents('li').children('.delete').fadeIn('fast');
}, function() {
$(this).parents('li').children('.delete').fadeOut('fast');
});
});
但是,如果我快速地将鼠标移入和移出图像,新的动画总是添加到队列中,当我停止时,我可以看到链接跳动了一段时间。我试着使用.stop(true),但有时淡入效果根本不起作用(或者只是达到某个小于1的不透明度值)。我能做什么
谢谢,Eric,最好的方法是使用插件。这涉及上述问题。它还增加了动画的轻微延迟,因此如果用户碰巧在所有链接上快速移动鼠标,则不会得到所有链接的丑陋动画流。防止出现此类问题的一种方法是将stop()与fadeTo()结合使用,如下面的代码段所示:
$(function() {
$('.delete').fadeTo(0, 0);
$('#photos img').hover(function() {
$(this).parents('li').children('.delete').stop().fadeTo('fast', 1);
}, function() {
$(this).parents('li').children('.delete').stop().fadeTo('fast', 0);
});
});
希望这能解决你的问题