当我有这个代码时:
$("img").each(function(i) {
$(this).delay(i*100).fadeIn('slow');
});
Run Code Online (Sandbox Code Playgroud)
...如何使这些图像以随机顺序出现?这意味着不是从左上角到右下角,而是随机像图像45,图像100,图像3等......?
http://blog.staydecent.ca/entry/jquery-random-each
function randsort(c) {
var o = new Array();
for (var i = 0; i < c; i++) {
var n = Math.floor(Math.random()*c);
if( jQuery.inArray(n, o) > 0 ) --i;
else o.push(n);
}
return o;
}
var e = $('div'); // The elements we're searching
var c = e.size(); // Total number of those elements
var r = randsort(c); // an array of the element indices in random order
$("div").each(function(i) {
var e = $(this);
e.fadeTo(0, 0.05);
setTimeout(function(){
e.fadeTo(250, 1);
}, r[i]*10);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1483 次 |
| 最近记录: |