jquery幻灯片,索引没有推进

时间:2011-04-28 10:47:03

标签: jquery indexing slideshow

大家好我遇到了无法解决的问题,我正在使用imageswitch制作幻灯片。

我有以下jquery:

// set up slideshow
    var IdxTR = <?php echo($totalRows_rs_gallery); ?>;
    var Idx =0;

    var ChangeImage = function(){  
        console.log('Idx: '+Idx+' - IdxTR: '+IdxTR+' Img: '+$(".SlImage").eq(Idx).attr("rel"));
        //If the image still animating, stop it and start the new one  
        $("#mainImage").ImageStop(true,true);  
        $("#mainImage").ImageSwitch({NewImage: $(".SlImage").eq(Idx).attr("rel")});    
        //Set the next image will be display  
        Idx = Idx++; 
        console.log('AFTER --- Idx: '+Idx+' - IdxTR: '+IdxTR+' Img: '+$(".SlImage").eq(Idx).attr("rel"));
        if(Idx>IdxTR){  
            Idx = 0;  
        }  
        //Start preload the next image  
        $.ImagePreload($(".SlImage").eq(Idx).attr("rel"));  
     };  
     var StartSlideShow = function(){
        IntervalKey = setInterval(ChangeImage,1000);
    };
StartSlideShow();

在我的HTML中我有:

<div id="topcontainer">
<img id="mainImage" src="images/gallery/<?php echo $row_rs_gallery['image_gly']; ?>" />
<?php do { ?>
  <div class="SlImage" rel="images/gallery/<?php echo $row_rs_gallery['image_gly']; ?>"/>
  <?php } while ($row_rs_gallery = mysql_fetch_assoc($rs_gallery)); ?>
</div>

第一个console.log输出:Idx:0 - IdxTR:8图:images / gallery / alison.jpg

但第二个consloe.log没有显示,当ChangeImage()函数再次运行时,idx没有进阶,第一个console.log输出相同: Idx:0 - IdxTR:8图:images / gallery / alison.jpg

为什么索引不提前的任何想法?或者为什么第二个console.log没有运行?

test page is here

1 个答案:

答案 0 :(得分:1)

您可能想要修复javascript首先出现的错误。它继续输出:

Idx: 0 - IdxTR: 8 Img: images/gallery/alison.jpg
jquery-1.4.3.min.js:55Uncaught TypeError: Cannot read property 'handler' of undefined
information3.php:20Idx: 0 - IdxTR: 8 Img: images/gallery/alison.jpg
jquery-1.4.3.min.js:55Uncaught TypeError: Cannot read property 'handler' of undefined
information3.php:20Idx: 0 - IdxTR: 8 Img: images/gallery/alison.jpg

等等。 错误似乎是在你的console.log之后,但是如果它在你的Idx ++之前,它永远不会从0更改,那就是你所看到的

此外:
现在我感到困惑(启动咖啡),但检查一下:
试试简单的Idx+1方式,或++Idx

来自this page(相当随机的页面,我承认)

var a = 5;
   b = a++;
    (b contains the initial value of a, which is 5.
    a, on the other hand is now equal to 6)

   var a = 5;
   c = ++a;
    (In this case, JavaScript first adds 1 to a, changing
    its value to 6. This value is returned to c.
    Thus, c = 6)

我不知道你的情况发生了什么,但请试试简单的+1方法吗?