未捕获的TypeError:$ .fn.snd_slider.external_move_to不是函数

时间:2016-03-11 23:23:43

标签: javascript jquery wordpress function scope

我正在创建一个wordpress主题但继续遇到标题中提到的错误。在过去的几天里,我一直试图找出为什么没有看到这个功能,但似乎无法找到解决方案。

在front-page.php中。我在谷歌地图中的标记点击事件中进行了以下函数调用。

$.fn.snd_slider.external_move_to( marker_order );

哪个函数位于我的main.js文件中。我为代码的长度道歉,但我认为有必要包括更多,以防我忽略了一些事情:

(function($){
    $.fn.snd_slider = function( options ) {
        var settings = $.extend( {
            slide                   : '.snd-slide',                 // slide class
            arrows                  : '.snd-slider-arrows',         // arrows container class
            prev_arrow              : '.snd-arrow-prev',            // left arrow class
            next_arrow              : '.snd-arrow-next',            // right arrow class
            controls                : '.snd-controllers a',         // control selector
            control_active_class    : 'snd-active-control',         // active control class name
            previous_text           : 'Previous',                   // previous arrow text
            next_text               : 'Next',                       // next arrow text
            fade_speed              : 500,                          // fade effect speed
            use_arrows              : true,                         // use arrows?
            use_controls            : true,                         // use controls?
            manual_arrows           : '',                           // html code for custom arrows
            append_controls_to      : '',                           // controls are appended to the slider element by default, here you can specify the element it should append to
            controls_class          : 'snd-controllers',            // controls container class name
            slideshow               : false,                        // automattic animation?
            slideshow_speed         : 7000,                         // automattic animation speed
            on_slide_changing       : function(){},                 // callback function that runs when a slide changes
            on_slide_change_end     : function(){}                  // callback function that runs when a slide changes
        }, options );

        return this.each( function() {
            var $snd_slider         = $(this),
                $snd_slide          = $snd_slider.find( settings.slide ),
                snd_slides_number   = $snd_slide.length,
                snd_fade_speed      = settings.fade_speed,
                snd_active_slide    = 0,
                $snd_slider_arrows,
                $snd_slider_prev,
                $snd_slider_next,
                $snd_slider_controls,
                snd_slider_timer,
                controls_html = '';

            if ( settings.use_arrows && snd_slides_number > 1 ) {
                if ( settings.manual_arrows == '' )
                    $snd_slider.append( '<div class="snd-slider-arrows"><a class="snd-arrow-prev" href="#">' + settings.previous_text + '</a><a class="snd-arrow-next" href="#">' + settings.next_text + '</a></div>' );    
                else
                    $snd_slider.append( settings.manual_arrows );

                $snd_slider_arrows  = $( settings.arrows );
                $snd_slider_prev    = $snd_slider_arrows.find( settings.prev_arrow );
                $snd_slider_next    = $snd_slider_arrows.find( settings.next_arrow );

                $snd_slider_next.click( function(){
                    snd_slider_move_to( 'next' );

                    return false;
                } );

                $snd_slider_prev.click( function(){
                    snd_slider_move_to( 'previous' );

                    return false;
                } );
            }

            if ( settings.use_controls && snd_slides_number > 1 ) {
                for ( var i = 1; i <= snd_slides_number; i++ ) {
                    controls_html += '<a href="#"' + ( i == 1 ? ' class="' + settings.control_active_class + '"' : '' ) + '>' + i + '</a>';
                }

                controls_html =
                    '<div class="' + settings.controls_class + '">' +
                        controls_html +
                    '</div>';

                if ( settings.append_controls_to == '' )
                    $snd_slider.append( controls_html );
                else
                    $( settings.append_controls_to ).append( controls_html );

                $snd_slider_controls    = $snd_slider.find( settings.controls ),

                $snd_slider_controls.click( function(){
                    snd_slider_move_to( $(this).index() );

                    return false;
                } );
            }

            snd_slider_auto_rotate();

            function snd__slider_auto_rotate(){
                if ( settings.slideshow && snd_slides_number > 1 ) {
                    snd_slider_timer = setTimeout( function() {
                        snd_slider_move_to( 'next' );
                    }, settings.slideshow_speed );
                }
            }

            function snd_slider_move_to( direction ) {
                var $active_slide = $snd_slide.eq( snd_active_slide ),
                    $next_slide;


                if ( direction == 'next' || direction == 'previous' ){

                    if ( direction == 'next' ){
                        console.log(snd_slides_number);
                        snd_active_slide = ( snd_active_slide + 1 ) < snd_slides_number ? snd_active_slide + 1 : 0;
                    }

                    else
                    {
                        snd_active_slide = ( snd_active_slide - 1 ) >= 0 ? snd_active_slide - 1 : snd_slides_number - 1;
                    }

                } else {

                    if ( snd_active_slide == direction ) return;

                    snd_active_slide = direction;

                }

                $next_slide = $snd_slide.eq( snd_active_slide );

                if ( settings.use_controls && snd_slides_number > 1 )
                    $snd_slider_controls.removeClass( settings.control_active_class ).eq( snd_active_slide ).addClass( settings.control_active_class );

                if ( settings.on_slide_changing )
                    settings.on_slide_changing( $next_slide );

                $active_slide.animate( { opacity : 0 }, snd_fade_speed, function(){
                    $(this).css('display', 'none');

                    $next_slide.css( { 'display' : 'block', opacity : 0 } ).animate( { opacity : 1 }, snd_fade_speed, function(){
                        if ( settings.on_slide_change_end )
                            settings.on_slide_change_end( $next_slide );
                    } );
                } );

                if ( typeof snd_slider_timer != 'undefined' ) {
                    clearInterval( snd_slider_timer );
                    snd_slider_auto_rotate();
                }
            }
            isitafunction = function(number){
                console.log(number);
            };
            $.fn.snd_slider.external_move_to = function( slide ) {
                snd_slider_move_to( slide );
            }
        } );
    }



})(jQuery)

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

我发现了我的问题的答案。这有点令人尴尬,但我意识到我没有调用返回我试图访问的函数的函数。错误是为了学习,对吧?