-1

I'm using the plugin backstretch for my site. If I want to use this in static mode I can do in this mode:

$.backstretch([
  "http://dl.dropbox.com/u/515046/www/outside.jpg"
   , "http://dl.dropbox.com/u/515046/www/garfield-interior.jpg"
   , "http://dl.dropbox.com/u/515046/www/cheers.jpg"]
   , {duration: 3000, fade: 750});

But if I want to do this in dynamic mode i have thinked to pass an array to teh backstretch like this:

 var arr2 = "[\"img/home/1.jpg\", \"img/home/2.jpg\"]";

 $.backstretch(
    arr2, {duration: 3000, fade: 750});

I have also tried:

var arr = new Array();
 for (var i=1; i<3; i++){
    arr.push("img/home/"+i+".jpg");
 }

But this doesn't work.. why?

4

1 回答 1

1

为什么在需要数组时将 arr2 设为字符串?尝试,

var arr2 = ["img/home/1.jpg", "img/home/2.jpg"]; 
$.backstretch(arr2, {duration: 3000, fade: 750});

编辑:(评论后)

你可以这样添加,

var arr2 = [];
arr2.push("img/home/1.jpg");
arr2.push("img/home/2.jpg");

等等...

您还可以在函数中传递多个参数push()

arr2.push("img/home/1.jpg","img/home/2.jpg");

参考

于 2012-11-19T15:29:31.707 回答