3

我制作了一个简单的鼠标进入和鼠标离开动画。当鼠标进入 div 时。比链接 div 会打开。鼠标移出时,div 将关闭。我用slideUp和slideDown设置了一个动画。

我的动画有问题。页面上有很多 .comment div。当我快速将鼠标悬停在项目上时。幻灯片动画很疯狂,你会看到很多次动画。我该如何解决?谢谢!

$("#comments .comment .links").hide();
$("#comments .comment").mouseenter(function() {
    $(".links",this).slideDown(300);
}).mouseleave(function() {
    $(".links",this).slideUp(300);
});
4

3 回答 3

6

用于stop(true)清除每个事件的动画队列:

$("#comments .comment .links").hide();
$("#comments .comment").mouseenter(function() {
    $(".links",this).stop(true).slideDown(300);
}).mouseleave(function() {
    $(".links",this).stop(true).slideUp(300);
});

此外,您可以使用以下代码压缩此代码hover()

$("#comments .comment .links").hide();
$("#comments .comment").hover(
    function() { $(".links", this).stop(true).slideDown(300); },
    function() { $(".links", this).stop(true).slideUp(300); }
);
于 2012-05-09T09:34:02.203 回答
2

你做什么行为?也许你可以在开始动画之前停止它为所有其他人设置动画

$("#comments .comment").mouseenter(function() {
    $("#comments .comment").stop();
    $(".links",this).slideDown(300);
}).mouseleave(function() {
    $(".links",this).slideUp(300);
});
于 2012-05-09T09:40:14.200 回答
0

这里同样的问题!

$("#spezial_navi_btn_20").mouseenter(function() {

    $("#content").stop(true).fadeOut("slow");
    $("#spezial_navi").css('background-image', 'url(http://#)');
    $("#spezial_navi_20").stop(true, true).slideUp("fast");
    $("#spezial_navi_desc_20").stop(true, true).slideDown('slow', function() {
        $("body").ezBgResize({
        img : "http://#",
        opacity : 1,
        center  : true 
        });
    });
    $("#spezial_navi_desc_30").stop(true, true).slideUp('slow');
    $("#spezial_navi_30").stop(true, true).slideDown('slow'); 
    $("#spezial_navi_desc_40").stop(true, true).slideUp('slow');
    $("#spezial_navi_40").stop(true, true).slideDown('slow'); 
});

解决了 !! 而不是: $("#spezial_navi_20").stop(true, true).slideUp("fast"); 和: $("#spezial_navi_desc_20").stop(true, true).slideDown('slow', function() { 我做了:$("#spezial_navi_20").slideUp("fast"); 和:$(" #spezial_navi_desc_20").slideDown('slow', function() {

于 2012-12-13T10:26:20.923 回答