未捕获的TypeError:...没有方法'dimTheLights'

时间:2011-08-24 08:16:35

标签: javascript jquery plugins

所以我正在编写一个小jQuery插件,但由于某种原因,插件方法根本没有被识别。任何人都可以找到我在下面出错的地方

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>

1 个答案:

答案 0 :(得分:0)

(然后我会把它作为答案;))

尝试使用window代替document