2011-04-28 44 views
0

嗨,人們有一個問題,我無法工作,我使用imageswitch來創建幻燈片。jquery幻燈片,索引不推進

我有以下的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圖:圖像/像冊/alison.jpg

但第二個consloe.log不顯示,並且當ChangeImage()函數再次運行時,idx不是高級的,並且第一個console.log輸出相同: Idx:0 - IdxTR:8圖:圖片/圖庫/ alison.jpg

任何想法爲什麼索引不先進?或爲什麼第二個console.log不運行?

test page is here

回答

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方法嗎?

+0

嗨,謝謝,我不能看到在螢火蟲的其他錯誤?我注意到了console.log和Idx ++之間的所有內容,第二個console.log現在運行,但索引仍然不是先進的 http://new.camerich.co.uk/information4.php?id_sec=2 – 2011-04-28 11:02:08

+1

添加了一些東西。嘗試這個? – Nanne 2011-04-28 11:11:04

+0

不錯,你可以把咖啡擱置一下......改變Idx = Idx + 1; 現在索引正在前進,有時間查看其他位,你用什麼來獲得這個錯誤?我在螢火蟲1.62,並沒有出現。 – 2011-04-28 11:16:39