2017-08-16 58 views
0

我正在使用JQuery創建幻燈片。幻燈片可與下面的代碼:幻燈片放映:在JQuery中淡入淡出

 function playSlideshow() { 

      timer = setInterval(function() { 

      thumbnails.children[currentNum].className = ''; 

       currentNum++; 
       if (currentNum > data.files.length - 1) { 
        currentNum = 0; 
        console.log(currentNum); 
       } 

       var currentImage = data.files[currentNum]; 
       target.src = currentImage; 

       thumbnails.children[currentNum].className = 'current'; 
       //playSlideshow(); 
      }, 3000);     
     } 

但是,我得到一個錯誤(currentImage.fadeIn不是一個函數),一旦我插入下面的代碼行:

function playSlideshow() { 

     timer = setInterval(function() { 

      thumbnails.children[currentNum].className = ''; 

      $('#main>img').fadeOut('slow'); 

      currentNum++; 
      if (currentNum > data.files.length - 1) { 
       currentNum = 0; 
      } 

      var currentImage = data.files[currentNum]; 
      //var image = data.files[currentNum].clone(true); 
      $('#main>img').prepend(currentImage.fadeIn('slow')); 
      target.src = currentImage; 

      thumbnails.children[currentNum].className = 'current'; 
      //playSlideshow(); 
     }, 3000);     
    } 

我得到了「文件'使用Ajax從JSON文件中獲取數組。 有沒有人有一個想法如何解決這個問題?

+0

將'currentImage'設置爲'File'對象嗎?什麼是'data.files'? – clabe45

+0

文件是我使用Ajax的JSON文件中的數組。數據是Ajax中函數的參數。 – mercredi

+0

數組的類型是什麼?它是否包含'HTMLElement',或者jQuery html元素,或者'Image',或者其他的東西? – clabe45

回答

0

嘗試jQuery對象,而不是在陣列對象上

$('#main>img').prepend(currentImage).fadeIn('slow'); 

褪色。

currentImage.fadeIn is not a function告訴你currentImage不是jQuery對象,或者fadeIn不存在於jQuery命名空間中。

+0

謝謝。錯誤消失了,但該項目正常工作而不會退色。 – mercredi