简体   繁体   English

用jQuery加载一组图像

[英]Loading in a set of images with Jquery

I have an array of images in jquery that I am attempting to load into a series of divs when the user clicks a specific box. 我在jquery中有一个图像数组,当用户单击特定框时,我试图将它们加载到一系列div中。 On my localhost everything works great, but when I put on the internets. 在我的本地主机上,一切正常,但是当我上网时。 Something really odd happens. 真的很奇怪。

在此处输入图片说明

the url that I am attempting to load is split into each individual character and separate div is created for each letter...? 我尝试加载的url被分为每个单独的字符,并为每个字母创建了单独的div ...?

here is the code that is used to create the div's and sign a background image to all of them. 这是用于创建div并为其签名的背景图像的代码。

            for (var i = 0, len = images[index].length; i < len; i++){
            $('#project_display #slides .slides_container').append($('<div></div>'))
            $('#project_display #slides .slides_container div').eq(i).css('background','url(' + images[index][i] +') center center no-repeat');
        }

images contains arrays of other images. 图像包含其他图像的数组。 any help would be so great! 任何帮助都将如此巨大!

thanks! 谢谢!

UPDATE 更新

here is images and another array creation: 这是图像和另一个数组创建:

` var circus = new Array(); `var circus = new Array(); circus[0] = 'images/projects/circus1.jpg'; circus [0] ='images / projects / circus1.jpg'; circus 1 = 'images/projects/circus2.jpg'; 马戏团1 ='images / projects / circus2.jpg'; circus[2] = 'images/projects/circus3.jpg'; circus [2] ='images / projects / circus3.jpg'; circus[3] = 'images/projects/circus4.jpg'; circus [3] ='images / projects / circus4.jpg'; circus[4] = 'images/projects/circus5.jpg'; circus [4] ='images / projects / circus5.jpg';

var images = new Array(); var images = new Array(); images[0] = 'images/projects/radioshack_899.jpg'; images [0] ='images / projects / radioshack_899.jpg'; images 1 = radioImages; 图片1 = radioImages; images[2] = dwarf; images [2] =矮人;
images[3] = dwarf; images [3] =矮人;
images[4] = circus; images [4] =马戏团; ` `

It's a little hard to tell without seeing more, but you are either doing something wrong in the for loop, or you are doing something wrong in the url(' + images[index][i] +') . 不了解更多内容很难说,但您要么在for循环中做错了事,要么在url(' + images[index][i] +')中做错了事。

Are you sure you that images.length is'nt what your looking for in the for loop, and something tells me you should remove the [i] in the url(), like so: url(' + images[index] +') 是否确定images.length不是for循环中要查找的内容,并且有什么告诉我您应该删除url()中的[i] ,例如: url(' + images[index] +')

Maybe it should be something like this: 也许应该是这样的:

for (var i = 0; i < images.length; i++){
    $('<div></div>').css('background','url(' + images[i] +') center center no-repeat')
       .appendTo($('#project_display #slides .slides_container'));
}

And you should try to shorten down those selectors if possible. 而且,如果可能,您应该尝试缩短这些选择器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM