1

下面的代码选择随机图像,我希望它线性选择并在下次刷新时显示接下来的 8 个图像。

$.fn.preload = function() {
    this.each(function(){
        $('<img/>')[0].src = this;
    });
}
function preloadImg(totalClients)
{
    for(var i = 1; i <= totalClients; i++)
    {
        $('<img src="images/clients/' + i + '.jpg"/>');
    }
}


function getRandoms(numPicks, low, high) {
    var len = high - low + 1;
    var nums = new Array(len);
    var selections = [], i;
    // initialize the array
    for (i = 0; i < len; i++) {
        nums[i] = i + low;
    }

    // randomly pick one from the array
    for (var i = 0; i < numPicks; i++) {
        var index = Math.floor(Math.random() * nums.length);
        selections.push(nums[index]);
        nums.splice(index, 1);
    }
    return(selections);
}

function randomClients(totalClients)
{
rarr = getRandoms(8,1,totalClients);
    $(".pretty-box").each(function(index)
    {
       $(this).fadeOut(function(){
           src = "images/clients/" + rarr[index] + ".jpg" ;
           $(this).attr('src',src);
           $(this).fadeIn();
       });
    });

}

我们能够从数组中选择前 8 张图像,但不能选择接下来的 8 张图像。有人可以帮助我们吗?

4

0 回答 0