简体   繁体   English

如何针对相同的多个实例 <div> .class一次单独一个?

[英]How to target multiple instances of same <div> .class individually one at a time?

I currently have x repeative setup of the same class: 我目前有x个相同类别的重复设置:

<div class="span3">..content1</div>
<div class="span3">..content2</div>
<div class="span3">..content3</div>

How do I target each .span3 class individually without adding some unique id for each of them? 如何在不为每个.span3类添加某些唯一ID的情况下分别为其定位? Is that even possible? 那有可能吗?

What I want to do is apply some animation on each .span3 at a time with a little delay inbetween each - like fading one .span3 class up at a time or do some other animation like scale from 0 to 1. 我想做的是一次在每个.span3上应用一些动画,在每个.span3之间稍加延迟-像一次使一个.span3类消失,或者做一些其他动画,例如从0缩放到1。

Was trying to figure out if I could somehow add them to an array? 是否在尝试找出是否可以将它们添加到数组中? And from there on id be able to iterate through the array doing whatever i wanted. 从那里开始,id可以遍历数组,做我想做的任何事情。

The .span class in more HTML context: .span类在更多HTML上下文中:

<div class="row-fluid">
      <div class="span3">
        <span>Headline</span>
        <img src="images/thumb_1.gif" class="img-polaroid">
      </div>
      <div class="span3 frameColor_yellow">
        <span>Headline</span>
        <img src="images/thumb_2.gif" class="img-polaroid">
      </div>
</div>
<div class="row-fluid">
      <div class="span3">
        <span>Headline</span>
        <img src="images/thumb_3.gif" class="img-polaroid">
      </div>
      <div class="span3 frameColor_yellow">
        <span>Headline</span>
        <img src="images/thumb_4.gif" class="img-polaroid">
      </div>
</div>
//etc...

Any suggestions? 有什么建议么?

Like this - 像这样 -

$('.span3').each(function(index,element){
    var sp = $(this);
    // do your stuff with this span
});

Try this: 尝试这个:

$(".row-fluid > .span3").each(function (index) {
    $(this).delay(index * 500).animate({
        opacity: 0
    }, 500);
});

FIDDLE 小提琴

Updated the answer based on @Rodrigo suggestion! 根据@Rodrigo建议更新了答案!

Proberbly you would like to wrap all your span3s inside a container, lets say 仔细地说,您想将所有span3包裹在一个容器中,可以说

<div class="my-loop-divs">
   <div class="span3"></div>
   <div class="span3"></div>
</div>

I assume that you are using zepto or jQuery 我假设您正在使用zepto或jQuery

$(document).ready(function () {
    $('.my-loop-divs .span3').each(function (index, element) {
        // do the animation on $(this)
    });
});

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

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