CSS
.item {
display: none;
}
html
<div>
<div class="item">machin</div>
<div class="item">chose</div>
<div class="item">chouette</div>
<div class="item">prout</div>
</div>
私はjQueryを使用しています。ランダムな小さなタイマーの後に各 .item
を表示させたいと思います。
JavaScript
$('.item').each(function() {
itm = $(this);
setTimeout(function() {
itm.fadeIn(1000);
}, Math.floor(Math.random() * 1000));
})
ここでは、すべての割り当ての後に関数が評価されるため、 itm
には常に最後の項目が含まれます。
IEで動作しないため、 setTimeout()
の3番目のパラメータは使用できません。
セキュリティ上の理由から、 setTimeout()
を eval メソッドと併用することはお勧めしません。
どうすれば setTimeout()
でオブジェクトにアクセスできますか?
編集
I know that this question have already been posted.
But I though that it were slightly specific with the each()
context.
Now someone have entirely changed the title of my question that was originally something like 'setTimeout() - jQuery.each() this object parameter'