2011-08-24 35 views
0

所以我在寫一個小jQuery插件,但由於某種原因,插件方法並不是在所有的認可。任何人都可以點在那裏我已經低於遺漏的類型錯誤:......沒有方法「dimTheLights」

jquery.dimlights.js

(function($) { 

    var settings = {  

     opacity  : 0.75, 
     center  : false, 

    } 

    var screen_width = $(document).width(); 
    var screen_height = $(document).height(); 

    $.fn.dimTheLights = function(options) { 

     // merge options into settings 
     options ? $.extend(settings, options) : false; 

     // add overlay to DOM 
     $('body').append('<div id="dtl_overlay"></div>'); 

     // resize overlay 
     $('#dtl_overlay').width(screen_width); 
     $('#dtl_overlay').height(screen_height); 

    }; 

})(jQuery); 


出錯的index.html

<html> 
    <head> 

     <title>Dim The Lights Demo</title> 

     <link rel="stylesheet" href="reset.css"> 
     <link rel="stylesheet" href="style.css"> 
     <link rel="stylesheet" href="../jquery.dimlights.css"> 

     <script src="http://code.jquery.com/jquery.min.js"></script> 
     <script src="../jquery.dimlights.js"></script> 
     <script> 

      $(document).ready(function() { 

       $('#content img').click(function() { 

        $(this).dimTheLights(); 

       }); 

      }); 

     </script> 

    </head> 

    <body> 

     <div id="wrapper"> 
      <header>Dim The Lights</header> 

      <section id="content"> 
       <img src="http://placekitten.com/278/100" class="dimthelights" /> 
      </section> 

      <footer> 
       <p>&copy; 2011 &bull; Jordan Adams</p> 

       <a href="http://twitter.com/jordancalluma">@JordanCallumA</a> 
      </footer> 
     </div> 

    </body> 
</html> 
+0

對我很好用:http://jsfiddle.net/TSkqF/1/你確定腳本的路徑和文件名是正確的嗎? – JJJ

+0

Yupp。他們正在加載罰款。再次照看不過我發現,jQuery是拋出一個錯誤 '遺漏的類型錯誤:無法讀取屬性「scrollWidth」 null' –

+0

的沒有關係,而是一個建議:當你沒有做與所選元素任何東西,我將延長'jQuery'。而不是'jQuery.fn'。然後你可以用'$ .dimTheLights()'調用該方法。 –

回答

0

(然後我會放它作爲答案;))

嘗試window而不是document

相關問題