我在#imacon
中有很多图像,我希望所有图像随机出现,但只出现1张图像。我该怎么办?
$(document).ready(function() {
var leng = $('#imacon').children().length;
var rm = Math.floor(Math.random()*leng);
setInterval(function() {
$('#imacon img:eq('+rm+')').fadeIn();
}, 500)
});
最佳答案
您需要在更改每个图像之后(或之前)更改随机数。
$(document).ready(function() {
var leng = $('#imacon').children().length;
setInterval(
function() {
var rm = Math.floor(Math.random()*leng);
$('#imacon img:eq('+rm+')').fadeIn();
},
500);
});