-3
var myArray = ['horizontal', 'vertical', 'fade'];
我試圖讓它MODE隨機..不能使它從陣列中發佈的隨機值
$(document).ready(function(){
$('.bx').b({
mode: 'fade'
auto: true,
});
});
var myArray = ['horizontal', 'vertical', 'fade'];
我試圖讓它MODE隨機..不能使它從陣列中發佈的隨機值
$(document).ready(function(){
$('.bx').b({
mode: 'fade'
auto: true,
});
});
你可以使用的Math.random()生成的索引使用對於myArray,例如
var id = Math.floor(Math.random()*myArray.length);
...
mode: myArray[id],
...
你只需要一個函數從數組中返回一個隨機元素:
function rand(arr) {
return arr[Math.floor(Math.random()*arr.length)];
}
將其組合在一起......
$(document).ready(function(){
$('.bx').b({
mode: rand(myArray)
auto: true,
});
});
我們不知道你的'B'插入。 – Lekhnath
@Lekhnath幸運的是我們也不需要知道。 – JJJ
@Juhana不幸的是,可能存在用於生成隨機值但由於某種原因無法工作的實現。 – Lekhnath