2016-01-06 81 views
0

我得到一個錯誤信息:「遺漏的類型錯誤:不能爲空的讀取屬性‘淡出’」的Joomla定製的jQuery的滑塊錯誤:「遺漏的類型錯誤:無法讀取屬性空的‘淡出’」

我的滑塊正在與分頁,但我收到了自動運行的錯誤信息

fadeOut()函數有什麼問題? 這裏是我的代碼:

jQuery.noConflict(); 

var speed = 3000; 
var effect = 600; 
run = setInterval("moveRight()", speed); 

jQuery(document).ready(function($){ 

    $('#slideshow > div:gt(0)').hide(); 
    $('#slideshow > div:first').addClass("currentslide"); 

    $("#slideshow-box").append('<div class="slide-nav"></div>'); 
    $("#slideshow > div").each(function(i) { 
     $('.slide-nav').append('<a></a>'); 
    }); 
    $('.slide-nav a:first').addClass("active"); 

    $(".slide-nav a").click(function() { 
     $(this).addClass("active"); 
     $(this).siblings().removeClass("active"); 
     var goslide = $(this).index(); 
     $('#slideshow > div').eq(goslide).siblings("div").fadeOut(effect); 
     $('#slideshow > div').eq(goslide).fadeIn(effect); 
     clearInterval(run); 
     run = setInterval("moveRight()", speed); 
    }); 
}); 

function moveRight() { 
var nextitem = $("#slideshow .currentslide").fadeOut(effect).removeClass('.currentslide').next('#slideshow > div'); 
if (nextitem.length === 0) { 
     nextitem = $('#slideshow > div').first(); 
    } 
    nextitem.fadeIn(effect).addClass('active'); 

    var a = $(".slide-nav a.active"); 
    if (a.length) { 
     var $next = a.next(); 
     if ($next.length == 0) $next = $(".slide-nav a").first(); 
     a.removeClass("active"); 
     $next.addClass("active"); 
    } 
}; 
+0

這意味着'$(「#幻燈片> DIV」 ).eq(goslide).siblings(「div」)沒有返回任何東西。看這裏。 – Antiga

+0

嘗試使用JavaScript調試器來清楚瞭解運行類型發生了什麼。打開檢查器 - >在出現錯誤的行上添加斷點並檢查所有對象和變量的值。 – roshan

回答

1

在你的函數moveRight$不等於jQuery。您需要將$重新分配給jQuery。有這樣做的多了,我想我更喜歡在全球關閉:

jQuery.noConflict(); 

(function($){ //Start closure 
    var speed = 3000; 
    var effect = 600; 
    run = setInterval("moveRight()", speed); 

    jQuery(document).ready(function($){ 

     $('#slideshow > div:gt(0)').hide(); 
     $('#slideshow > div:first').addClass("currentslide"); 

     $("#slideshow-box").append('<div class="slide-nav"></div>'); 
     $("#slideshow > div").each(function(i) { 
      $('.slide-nav').append('<a></a>'); 
     }); 
     $('.slide-nav a:first').addClass("active"); 

     $(".slide-nav a").click(function() { 
      $(this).addClass("active"); 
      $(this).siblings().removeClass("active"); 
      var goslide = $(this).index(); 
      $('#slideshow > div').eq(goslide).siblings("div").fadeOut(effect); 
      $('#slideshow > div').eq(goslide).fadeIn(effect); 
      clearInterval(run); 
      run = setInterval("moveRight()", speed); 
     }); 
    }); 

    function moveRight() { 
    var nextitem = $("#slideshow .currentslide").fadeOut(effect).removeClass('.currentslide').next('#slideshow > div'); 
    if (nextitem.length === 0) { 
      nextitem = $('#slideshow > div').first(); 
     } 
     nextitem.fadeIn(effect).addClass('active'); 

     var a = $(".slide-nav a.active"); 
     if (a.length) { 
      var $next = a.next(); 
      if ($next.length == 0) $next = $(".slide-nav a").first(); 
      a.removeClass("active"); 
      $next.addClass("active"); 
     } 
    }; 
})(jQuery);//Call closure 

你也可以簡單地設置一個局部變量來$

function moveRight() { 
    var $ = jQuery; // Set jQuery for this scope 
    var nextitem = $("#slideshow .currentslide").fadeOut(effect).removeClass('.currentslide').next('#slideshow > div'); 
    if (nextitem.length === 0) { 
     nextitem = $('#slideshow > div').first(); 
    } 
    nextitem.fadeIn(effect).addClass('active'); 

    var a = $(".slide-nav a.active"); 
    if (a.length) { 
     var $next = a.next(); 
     if ($next.length == 0) $next = $(".slide-nav a").first(); 
     a.removeClass("active"); 
     $next.addClass("active"); 
    } 
}; 
+0

非常感謝!我設置了局部變量,它現在可以工作了! –

相關問題