0

I have this function which works fine except for updating the gallery information... but when i paste the code snippet in the console (chrome developer tool) it works just fine.. Here is what i paste in the console:

var obj = $('.item_info'),
arr = $.makeArray(obj);
$(".gallery-info").html(arr[0]);

Here is the complete function.

setTimeout(function() { 
// If it is the about us page
if($(".page-id-7").length < 1) {
// if it has bullets
    if($(".rsBullets").length) {
        // move the bullets html
        $(".slider_down .pull-right").addClass("rsUni").prepend($(".rsNav"));       
    }
}
// if page has thumbnails
if($(".rsThumbs").length) {
    // get the slider
    var slider = $(".royalSlider").data('royalSlider');
    // move the thumbnail html
    $(".footer .container-fluid").addClass("rsUni").prepend($(".rsNav"));
    $(".rsNav").toggle();
    // get all divs with the class item-info in an array
    var obj = $('.item_info'),
        arr = $.makeArray(obj);
    // set the gallery-info html to the first item in the array
    $(".gallery-info").html(arr[0]);
    $("#slider_prev").click(function() {
        slider.prev();
    });
    $("#slider_next").click(function() {
        slider.next();
    });
    var curId, totalSlides = slider.numSlides;
    $("#slide_count").html("1 OF "+totalSlides);
    // after slider change
    slider.ev.on('rsAfterSlideChange', function(event) {
        curId = slider.currSlideId + 1;
        // update the count
        $("#slide_count").html(curId+" OF "+totalSlides);
        // update the gallery info to the current item
        $(".gallery-info").html(arr[slider.currSlideId]);
    });
    $(".royalSlider").height("640");
}
}, 0);

$(".gallery-info").html(arr[0]); just below this line i tried to alert(arr[0]) which gives undefined.

Also any performance tips will be appreciated. Thanks

4

1 回答 1

1

我只是尝试在第一个超时功能中使用另一个超时功能..不确定这是否是最好的做法,但现在它对我有用..我不会将此作为正确答案并等待任何更好的答案。

setTimeout(function() { 
    var obj = $('.item_info'),
            arr = $.makeArray(obj);
            $(".gallery-info").html(arr[0]);
            slider.ev.on('rsAfterSlideChange', function(event) {
             curId = slider.currSlideId + 1;
                $("#slide_count").html(curId+" OF "+totalSlides);
                $(".gallery-info").html(arr[slider.currSlideId]);
            });
        }, 700);
于 2013-03-13T14:14:42.233 回答