开发者

"$.______ is not a function" error. What is wrong?

开发者 https://www.devze.com 2023-03-16 12:30 出处:网络
I\'m trying to add an image rotator to my site but for some reason firebug tells me the function I need to call to start the rotator isn\'t defined. My jQuery file is loading just fine and the image r

I'm trying to add an image rotator to my site but for some reason firebug tells me the function I need to call to start the rotator isn't defined. My jQuery file is loading just fine and the image rotator script is loading so I'm not sure what is wrong. The site is heritage.newcoastmedia.com but I'll go ahead and post the script:

;(function($) {
    $.fn.featureList = function(options) {
        var tabs    = $(this);
        var output  = $(options.output);

        new jQuery.featureList(tabs, output, options);

        return this;    
    };

    $.featureList = function(tabs, output, options) {
        function slide(nr) {
            if (typeof nr == "undefined") {
                nr = visible_item + 1;
                nr = nr >= total_items ? 0 : nr;
            }

            tabs.removeClass('current').filter(":eq(" + nr + ")").addClass('current');

            output.stop(true, true).filter(":visible").fadeOut();
            output.filter(":eq(" + nr + ")").fadeIn(function() {
                visible_item = nr;  
            });
        }

        var options         = options || {}; 
        var total_items     = tabs.length;
        var visible_item    = options.start_item || 0;

        options.pause_on_hover      = options.pause_on_hover        || true;
        option开发者_运维百科s.transition_interval = options.transition_interval   || 5000;

        output.hide().eq( visible_item ).show();
        tabs.eq( visible_item ).addClass('current');

        tabs.click(function() {
            if ($(this).hasClass('current')) {
                return false;   
            }

            slide( tabs.index( this) );
        });

        if (options.transition_interval > 0) {
            var timer = setInterval(function () {
                slide();
            }, options.transition_interval);

            if (options.pause_on_hover) {
                tabs.mouseenter(function() {
                    clearInterval( timer );

                }).mouseleave(function() {
                    clearInterval( timer );
                    timer = setInterval(function () {
                        slide();
                    }, options.transition_interval);
                });
            }
        }
    };
});

And here is the script to start the image rotator:

<script language="javascript">
    $(document).ready(function() {

        $.featureList(
            $("#tabs li a"),
            $("#output li"), {
                start_item  :   1
            }
        );
    });
</script>


Your code creates an anonymous function, but doesn't call it.

You need to call the function by adding (jQuery) at the end.


You cannot do $.featureList(

See Chrome error:

"$.______ is not a function" error. What is wrong?

The plugin needs to applied to an object


You've just slightly missed out on the right syntax for creating a plugin. What you really want is:

(function($) {
   $.fn.featureList = function() { // etc; }
   $.featureList = function() { // yet more etc; }
})(jQuery);
0

精彩评论

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