jQuery随机时间图像随机时间在几个tds

时间:2015-02-08 08:10:13

标签: jquery

我有一个包含4行和7列的表。在每个td我放置了一个链接(a)与三个随机图像(由PHP创建没有问题:))。这个想法是无限地淡化和淡化三个图像。 问题是我希望每个td的图像在不同的随机时间淡入淡出,而不是同时出现。 我试过这个,但我对jQuery很新。

HTML:

<table>
<tbody>
<tr>
    <td><a href="#" class="casella"><img src="" /><img src="" /><img src="" /></a></td>
    <td><a href="#" class="casella"><img src="" /><img src="" /><img src="" /></a></td>
    ...till 7 columns
</tr>
<tr... till 4 rows
</tbody>
</table>

JQUERY:

$(window).load(function(){
$(".casella").each(function(i,el) anim() {
 $(el "img").first().fadeOut(1500);
 $(el "img").first().fadeIn(1500);
 setTimeout(anim, 3000);
}
            anim();})

CSS:

a.casella {position:relative;} 
a.casella img{position: absolute; left:0; top:0; display:none; z-index:-1; width:120px; height:120px}

1 个答案:

答案 0 :(得分:0)

这里有语法错误:

$(window).load(function(){
$(".casella").each(function(i,el) anim() {
 $(el "img").first().fadeOut(1500);
 $(el "img").first().fadeIn(1500);
 setTimeout(anim, 3000);
}
            anim();})

应该是:

$(window).load(function(){
    $(".casella").each(function anim(i,el) {
         $("img",el).first().fadeOut(1500);
         $("img",el).first().fadeIn(1500);
         setTimeout(anim, 3000);
    });
});

请参阅第二行 - 参数后面有anim()

另外,我用选择器解决了这个问题。

还有更多语法错误。