2012-02-20 101 views
10

財產「節點名稱」這個問題只出現在的Joomla -遺漏的類型錯誤:無法讀取的不確定

我嘗試使用contentflow插件與Joomla網站

這是插件的網站 - http://www.jacksasylum.eu/ContentFlow/

這是我的地盤 - http://2-dweb.com/RND/

,你可以看到它不工作 - 它只是停留在加載階段永遠

仔細檢查後我可以看到,有一個與此代碼的問題:

if (this.content.nodeName == "IMG") { 
    CFobj._imagesToLoad++; 

    var foobar = function() { 
     CFobj._imagesToLoad--; 
     this.image = this.content; 
     this.setImageFormat(this.image); 
     if (CFobj.conf.reflectionHeight > 0) { 
      this.addReflection(); 
     } 
     this.initClick(); 
     CFobj._addItemCueProcess(true); 
    }.bind(this); 

    if (this.content.complete && this.content.width > 0) 
     window.setTimeout(foobar, 100); 
    else if (this.Browser.IE && !this.content.onload) { 
     var self = this; 
     var t = window.setInterval(function() { 
      if (self.content.complete && self.content.width > 0) { 
       window.clearInterval(t); 
       foobar(); 
      } 
     }, 10); 
    } 
    else 
     this.content.onload = window.setTimeout(foobar, 100); 
} 
else { 
    this.initClick(); 
    CFobj._addItemCueProcess(true); 
} 

}; 

於第一線 - 它說:「遺漏的類型錯誤:無法讀取屬性‘節點名稱’的未定義」

但這東西適用於我的桌面html文件和插件網站它自己!

爲什麼它不能在我的joomla網站上工作? 它不是一個矛盾的東西 - 不使用衝突和我有工作,其他的jQuery插件IM

更新:

搶劫W的這個錯誤讓我: 「第一行更改爲IF(this.content 。& & this.content.nodeName == 「IMG」){能解決問題」

,它做了,但是現在出現另一個錯誤:

initClick: function() { 
     var cItem = this.clickItem; 
     this[this._activeElement].addEvent('click', cItem, false); 
    }, 

錯誤 - Uncaught TypeError:無法調用未定義的方法'addEvent'

+0

將第一行更改爲'if(this.content && this。content.nodeName ==「IMG」){'。解決了這個問題。 – 2012-02-20 14:17:27

+0

確定它修復了一個問題,但現在在這個代碼上有一個問題: initClick:function(){ var cItem = this.clickItem; this [this._activeElement] .addEvent('click',cItem,false); } 它說:「遺漏的類型錯誤:無法調用方法的不確定‘的addEvent’」 – 2012-02-20 14:31:52

+0

試圖與鐵軌(3.2.15),使用時發現一個相同的問題 - 通過'contentflow'寶石使用時,甚至適用。 – 2013-12-08 15:02:48

回答

9

由於錯誤解釋爲「Uncaught TypeError:無法讀取未定義的屬性'nodeName'」當腳本嘗試訪問它時,該元素不可用。你可以用兩種方法來解決這個問題。

  • 嘗試使用document.ready打包到代碼。
  • 您可以在訪問它之前檢查元素是否可用。爲了完成這個工作,使用if子句。
+0

我認爲文件中的JS可能已經包裝在'document.ready'中,但我一定會檢查。 – 2013-12-11 09:09:18

+0

看起來不是這樣。我認爲這可能與綁定有關,但似乎沒有任何效果。 – 2013-12-15 19:28:06

1

將所有元素加載到DOM後,僅加載腳本

你的腳本應該在頁面的底部這樣調用

<html> 
    <head></head> 

    <body> 
    <!--HTML Elements here--> 

    <script type="text/javascript" src="yourScript.js"></script> 
    </body> 
</html> 

如果你是使用jQuery,您可以包括腳本文件在你的頁面的任何地方,如果它被包裹在document.ready,像這個:

$(document).ready(function(){ 

    // your code here.. 

}); 
1

重要的是你使用class="content"。結構應爲:

<div class="ContentFlow" id="cover-menu"> 
     <div class="flow"> 
      <div class="item" > 
       <div class="content"> 
        //your stuff 
       </div> 
      </div> 
     </div> 
</div> 
相關問題