i’m using the Jquery Supersized plugin and wanted a better way of creating the list of images used.
i found this same question here jQuery Supersized: Load images from LI but i’m having trouble implementing the solution.
i have a UL with the names of the images like this :
<ul id="slide_list">
<li><div class="slide_src">pic1.jpg</div>
<div class="slide_head">head 1</div></li>
<li><div class="slide_src">pic2.jpg</div>
<div class="slide_head">head 2</div></li>
<li><div class="slide_src">pic3.jpg</div>
<div class="slide_head">head 3</div></li>
</ul>
i then use the code jfriend00 provided to create an array from this list :
var slides = [];
$("ul .image").each(function() {
var this$ = $(this);
var obj = {};
obj.image = this$.text();
obj.title = this$.nextAll(".slide_src").text();
obj.thumb = this$.nextAll(".slide_head").text();
slides.push(obj);
});
my problem is that when i try to use this slides array in the supersized script it gives me an error “‘slides’ is undefined”
my supersized code looks like this :
jQuery(function($){
$.supersized({
//Functionality
slideshow : 1, //Slideshow on/off
autoplay : 1, //Slideshow starts playing automatically
start_slide : 1, //Start slide (0 is random)
random : 0, //Randomize slide order (Ignores start slide)
slide_interval : 5000, //Length between transitions
//Components
navigation : 0, //Slideshow controls on/off
thumbnail_navigation : 0, //Thumbnail navigation
slide_counter : 0, //Display slide numbers
slide_captions : 0, //Slide caption (Pull from "title" in slides array)
slides : slides
});
});
(i’ve removed some of the supersized option code for brevity).
showing the content of slides array in the console shows me
[object Object],[object Object],[object Object]
so i know i’m doing something wrong…
if i use this :
slidesDisp = JSON.stringify(slides)
then the array is shown perfectly in the console,
[{"image":"pic1.jpg","title":"head 1"},{"image":"pic2.jpg","title":"head 2"},{"image":"pic3.jpg","title":"head 3"}]
but when i use it in the supersized script nothing happens
slides: slidesDisp
any suggestions to what i’m doing wrong?
Your HTML does’nt match your javascript, you don’t have an
.imageclass, and make sure you don’t initalize the supersized plugin in a different DOM ready scope :