简体   繁体   English

jQuery Supersized:如何使用从LI创建的数组?

[英]jQuery Supersized: how to use array created from LI?

i'm using the Jquery Supersized plugin and wanted a better way of creating the list of images used. 我正在使用Jquery Supersized插件,并希望有一种更好的方法来创建使用的图像列表。

i found this same question here jQuery Supersized: Load images from LI but i'm having trouble implementing the solution. 我在这里找到了同样的问题jQuery Supersized:从LI加载图像,但是我在实施解决方案时遇到了麻烦。

i have a UL with the names of the images like this : 我有这样的图像名称的UL:

<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 : 然后,我使用提供的代码jfriend00从此列表创建数组:

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" 我的问题是,当我尝试在超大号脚本中使用此slides数组时,出现错误“'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 在控制台中显示slides数组的内容向我展示
[object Object],[object Object],[object Object] so i know i'm doing something wrong... [object Object],[object Object],[object Object]所以我知道我做错了...

if i use this : slidesDisp = JSON.stringify(slides) 如果我使用这个: 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 那么该数组将在控制台中完美显示[{"image":"pic1.jpg","title":"head 1"},{"image":"pic2.jpg","title":"head 2"},{"image":"pic3.jpg","title":"head 3"}]但是当我在超大型脚本中使用它时,什么也没有发生

slides: slidesDisp

any suggestions to what i'm doing wrong? 任何建议,我在做什么错了?

Your HTML does'nt match your javascript, you don't have an .image class, and make sure you don't initalize the supersized plugin in a different DOM ready scope : 您的HTML与您的JavaScript不匹配,没有.image类,并确保不要在其他DOM ready范围内.image超大插件:

$(function() {

    var slides = [];    

    $("ul .slide_src").each(function() {
        var $this = $(this);
        var obj = {};
        obj.image = $this.text();
        obj.title = $this.next(".slide_head").text();
        slides.push(obj);
    });​​​​​​​​​​​​​​​

    $.supersized({
        // ...........other options
        slides                  : slides
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM