两个幻灯片函数,幻灯片图像数组格式不一样(一个之前有 src: 文本),我需要两个函数使用相同的变量,所以我不想创建两个数组,我不知道该怎么做,有什么简单的方法吗?这是代码
第一个幻灯片功能
$('#slide').slideshow1({
preload: true,
timer: true,
// alot of other setting
// i need use variable here, ie. slide: slide_image_array
slides: [
{src: 'img/slide-image-01.jpg'},
{src: 'img/slide-image-02.jpg'},
{src: 'img/slide-image-03.jpg'}
]
});
}
另一个幻灯片功能
function slideshow2(){
$.backstretch([
// i need use same variable here, ie. slide_image_array
'img/slide-image-01.jpg',
'img/slide-image-02.jpg',
'img/slide-image-03.jpg'
],
{duration: 1000, fade: 800});
}
两个问题
如何使用一个变量“slide_image_array”来存储两个函数的图像集?
在“slide_image_array”数组中,如何有一个变量来输入数字,即。数字是8,然后自动设置slide-image-01.jpg - slip-image-08.jpg,使用每个功能吗?请给我一些提示
非常感谢:)
最佳答案
尝试
var backstretch = [
// i need use same variable here, ie. slide_image_array
'img/slide-image-01.jpg',
'img/slide-image-02.jpg',
'img/slide-image-03.jpg'
];
var slideshow = backstretch.map(function(val) {
return {"src":val}
});
$('#slide').slideshow1({
preload: true,
timer: true,
// alot of other setting
// i need use variable here, ie. slide: slide_image_array
slides: slideshow
});
// }
function slideshow2(){
$.backstretch(backstretch,
{duration: 1000, fade: 800});
}
关于jquery 两个函数使用相同的数组变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29112803/