开发者

Uncaught TypeError: ... no method 'dimTheLights'

So I'm writing a little jQuery plugin but for some reason the plugin method isn't being recognised at all. Can anyone spot where I've gone wrong below

jquery.dimlights.js

(function($) {

    var settings = {    

        opacity     : 0.75,
        center      : false,

    }

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

    $.fn.开发者_StackOverflow社区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>


(Then I will put it as an answer ;))

Try window instead of document.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜