假设我有一组图像。现在我希望始终具有相同的顺序,但起始位置不同。我可以在 Backstretch 中强制索引,但不能在它已经启动第一个图像之前,所以自然地,我只想偏移数组。
['1','2','3','4']
应该变成,取决于随机变量
['3','4','1','2'].
我怎样才能实现这个目标?
最佳答案
TJ Crowders 的回答非常好,但为了保持秩序,这里是我的 2 美分
var arr = ['1', '2', '3', '4']; //your source array
var rand = Math.round(Math.random()*arr.length); //get the random
var part = arr.splice(0, rand); //split from start to that number
arr = arr.concat(part); //concat back to push the part to the end for the order to be preserved.
//get your item arr[0]
Fiddle
关于javascript - Javascript 中的偏移数组顺序与 Backstretch 插件一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17014837/