【问题标题】:Stopping jQuery animations from queuing?停止 jQuery 动画排队?
【发布时间】:2014-02-14 16:39:41
【问题描述】:

编辑 17/2/14:我尝试使用 .toggle JQuery 函数来解决此问题,但它似乎不适用于我当前的设置。我一直在 Chrome 的开发控制台中密切关注它,当它尝试执行时它实际上什么也没做。这是更新的代码:

$(document).ready(function(){ 
$(".remove").toggle(function() { 
                 $($(this).attr("data-ref")).stop(true,true).fadeIn();
                  },
                   function() { 
                 $($(this).attr("data-ref")).stop(true,true).fadeOut();
                });
});

旧:

我正在尝试为每个悬停的图像地图区域显示一个独特的工具提示,但是当它们动画淡入或滑入时,它们要么一个接一个地排队并动画,剪辑在后面如果一次悬停了很多图像,或者根本没有动画。

这是我的代码。我宁愿不更改标记:

悬停在:1 悬停:2 悬停:3 悬停:4 悬停在:5

$('.remove').mouseover(function(){ $($(this).attr("data-ref")).show(); });

$('.remove').mouseout(function(){ $($(this).attr("data-ref")).hide(); });

【问题讨论】:

  • 试试$($(this).attr("data-ref")).stop(true).fadeIn();$($(this).attr("data-ref")).stop(true).fadeOut();
  • 我似乎仍然遇到同样的问题,几个 div 一个接一个地淡入淡出,动画播放之间没有中断,或者根本没有播放。

标签: jquery jquery-animate


【解决方案1】:

使用.stop(true,true

$($(this).data("ref")).stop(true,true).fadeIn();

.data()

.fadein()

【讨论】:

  • 这似乎效果最好。我仍然在叠加动画,但我会尝试使用停止值,看看是否可以让某些东西正常工作。
  • 另外: .data("ref") 似乎不起作用。 .data 是否根据我的属性插入连字符?我把它改回 .attr("data-href") 就很好了。
【解决方案2】:

就这样做吧:

$('.remove').mouseover(function(){
$($(this).attr("data-ref")).stop();
$($(this).attr("data-ref")).show();
});

$('.remove').mouseout(function(){
$($(this).attr("data-ref")).stop();
$($(this).attr("data-ref")).hide();
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-14
    • 1970-01-01
    • 1970-01-01
    • 2012-03-02
    相关资源
    最近更新 更多