简体   繁体   English

匹配集合上的jQuery队列

[英]jQuery queue on matched set

I'm trying to trigger a sequence of effects (simple animated show/hide) on a group of images inside of div where images are tagged with classnames that provide a filtering ability thru class selectors. 我正在尝试在div内的一组图像上触发一系列效果(简单的动画显示/隐藏),其中图像被标记有通过类选择器提供过滤功能的类名。

<div id="myDiv">
    <img class="tag1 tag2 tag3" ... />
    <img class="tag2 tag3" ... />
    <img class="tag1 tag2" ... />
    ...more image tags...
</div>

Now, I want to show the images matching a tag like: 现在,我想显示与标签类似的图像:

$('#myDiv .tag1').hide('blind', {}, 300);    
$('#myDiv .tag2').show('blind', {}, 300);

Where tag1 was the old active tag and tag2 is the new active tag. 其中tag1是旧的活动标签,而tag2是新的活动标签。 I thought I could just drop the show function into a callback on the hide function call, but it ends up calling the show method repeatedly (as many times as there were items hidden in the first call). 我以为我可以将show函数放到hide函数调用的回调中,但最终会反复调用show方法(与第一次调用中隐藏的项一样多)。

Could anyone suggest how to use the callback only once on the first matched set, or provide another way to use jQuery's queue to pull these off in sequence? 谁能建议如何在第一个匹配集上仅使用一次回调,或者提供另一种使用jQuery的队列按顺序提取回调的方法? The challenge as I see it is that the show effect doesn't necessarily impact the same images that were hit with the hide effect. 我所面临的挑战是,显示效果不一定会影响用隐藏效果击中的相同图像。

One thing I tried was using a facilitating element where I could attach the effects (like assigning them on a queue on myDiv) but I couldn't see a way to make that work properly. 我尝试的一件事是使用一个促进元素,我可以在其中附加效果(例如将其分配到myDiv上的队列中),但是我看不到一种使效果正常工作的方法。

Thanks! 谢谢!

What I would do is make a variable that you can store if the show has been fired then wrap the call for the show in an if check. 我要做的是创建一个变量,如果节目被解雇,则可以存储该变量,然后将对节目的调用包装在if检查中。 What ever event triggers the hides before you fire them reset this variable. 触发皮革之前发生的任何事件都会触发该皮革重置此变量。 That should insure that the show will fire only once after the hides. 那应该确保该演出在生皮之后仅触发一次。

var fired = false;

function showhide()
{
  fired=false;
  $('#myDiv .tag1').hide('blind', function(){
    if(!fired)
    {
      fired=true;
      $('#myDiv .tag2').show('blind', {}, 300);
    }
  }, 300);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM