我需要将此 div 内的图像的属性添加到 JS 数组并使用这些图像运行 Supersized:
<div id="dgaslides">
<img src="img/temp/topimg01.jpg" title="Image 1">
<img src="img/temp/topimg02.jpg" title="Image 2">
<img src="img/temp/topimg03.jpg" title="Image 3">
</div>
我的 JS:
jQuery(function($){
var img_length = $('#dgaslides img').length-1;
var dgaslides = [];
$('#dgaslides img').each( function(i){
var src = $(this).attr('src');
var title = $(this).attr('title');
dgaslides.push("{image : '" + src + "', title : '" + title + "'}");
if(img_length == i){
$.supersized({
// Functionality
slide_interval : 3000, // Length between transitions
transition : 1, // 0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
transition_speed : 700, // Speed of transition
horizontal_center : 1, // Centers image horizontally. When turned off, the images resize/display from the left of the page.
// Components
slide_links : 'blank', // Individual links for each slide (Options: false, 'num', 'name', 'blank')
slides : dgaslides
});
}
}); });
它确实有效,因为我在输出中获得了 3 张图像,但是链接(src)是“未定义”,并且标题也不存在?
硬编码的正确方法是:
var dgaslides = [ // Slideshow Images
{image : 'img/temp/topimg01.jpg', title : 'Reception'},
{image : 'img/temp/topimg02.jpg', title : 'Reception 2 og noget mere tekst her'},
{image : 'img/temp/topimg03.jpg', title : 'Reception 3'}
];
谁能帮我弄清楚我做错了什么?