未捕获的SyntaxError:意外的令牌=

时间:2014-01-17 07:16:17

标签: javascript jquery google-chrome joomla2.5

我正在使用滑块在Joomla中滚动图像,但是我的js在火狐中工作正常,但它显示未捕获

SyntaxError:

  

意外的令牌= chrome中的错误

我的代码是:

var $j = jQuery.noConflict();
$j(document).ready(function () {
 function animateThumbs( direction, $item, val, opacity ) {
        var ani = {
            opacity: opacity
        };
        ani[ getMarginProperty() ] = val;

        if ( direction == 'next' ) {
            var x1 = '.t1',
                x2 = '.t2, .t4',
                x3 = '.t3, .t5, .t7',
                x4 = '.t6, .t8',
                x5 = '.t9';
        } else {
            var x1 = '.t9',
                x2 = '.t6, .t8',
                x3 = '.t3, .t5, .t7',
                x4 = '.t2, .t4',
                x5 = '.t1';
        }

        $j(x1, $item).delay( _duration * 0    ).animate( ani, _duration );
        $j(x2, $item).delay( _duration * 0.25 ).animate( ani, _duration );
        $j(x3, $item).delay( _duration * 0.5  ).animate( ani, _duration );
        $j(x4, $item).delay( _duration * 0.75 ).animate( ani, _duration );
        $j(x5, $item).delay( _duration * 1    ).animate( ani, _duration );
    }
    function getMarginProperty() {
        return ( _orientation == 'horizontal' ) ? 'marginLeft' : 'marginTop';
    }
    function getMargin( direction ) {
        var margin = ( $window[ ( _orientation == 'horizontal' ) ? 'width' : 'height' ]() / 2 ) + 210
        if ( direction == 'next' )
        {
            margin = -margin;
        }
        return margin;
    }

    var $window = $j(window),
        $inner = $j('#inner'),
        $carousel = $j('#carousel');

    var _orientation = 'horizontal',
        _duration = 500,
        _animating = false;

    $inner.show();
    $carousel.carouFredSel({
        width: '100%',
        height: '100%',
        circular: false,
        infinite: false,
        direction: 'right',
        items: 1,
        auto: false,
        scroll: {
            fx: 'none',
            timeoutDuration: 500,
            conditions: function( direction ) {

                _animating = true;

                if ( $carousel.hasClass( 'prepared' ) )
                {
                    $carousel.removeClass( 'prepared' );
                    return true;
                }

                $carousel.addClass( 'prepared' );

                animateThumbs( direction, $carousel.children().first(), getMargin( direction ), 0 );

                setTimeout(
                    function() {
                        $carousel.trigger( direction );
                    }, _duration + 300
                );

                return false;
            },
            onBefore: function( data ) {
                var direction = data.scroll.direction;

                var css = {
                    opacity: 0
                };
                css[ getMarginProperty() ] = -getMargin( direction );

                $j('img', data.items.visible).css( css );
                animateThumbs( direction, data.items.visible, 0, 1 );
            },
            onAfter: function( data ) {
                data.items.old.children().css({
                    'marginLeft': 0,
                    'marginTop': 0
                });

                setTimeout(
                    function() {
                        _animating = false;
                    }, _duration + 800
                );
            }
        }
    });

    $carousel.trigger("currentPosition", function( pos=<?php echo 1;?> ) {
        console.log(pos);
        var posi = pos;
    });

    $j('#left').click(function() {
        if ( _animating ) {
            return false;
        }

        var direction = this.id,
            scroll = 'prev',
            newOrientation = ( direction == 'up' || direction == 'down' ) ? 'vertical' : 'horizontal';

        if ( _orientation != newOrientation ) {
            _orientation = newOrientation;
            $inner.toggleClass( 'horizontal' ).toggleClass( 'vertical' );
            $carousel.trigger( 'configuration', [ 'direction', direction ] );
        }

        $carousel.trigger("currentPosition", function( pos=2) {
            //console.log(pos);

            if(pos > 0 && pos <= 1)
            {
                $carousel.trigger( scroll );
            }
        });

        return false;
    });

    $j('#right').click(function() {
            if ( _animating ) {
                return false;
            }

            var direction = this.id,
                scroll = 'next',
                newOrientation = ( direction == 'up' || direction == 'down' ) ? 'vertical' : 'horizontal';

            if ( _orientation != newOrientation ) {
                _orientation = newOrientation;
                $inner.toggleClass( 'horizontal' ).toggleClass( 'vertical' );
                $carousel.trigger( 'configuration', [ 'direction', direction ] );
            }

            $carousel.trigger("currentPosition", function( pos ) {
                //console.log(pos);

                if(pos < <?php echo $poscount-1; ?>)
                {
                    $carousel.trigger( scroll );
                }
            });

            return false;
        });


    $j('a[href=#]').click(function(){
        return false;
    });
});

任何人都可以建议我出错吗?

由于

2 个答案:

答案 0 :(得分:1)

您没有为错误提供行号,但是看到您的代码我认为错误位于以下行:$carousel.trigger("currentPosition", function( pos=<?php echo 1;?> ) {

javascript不允许这样的默认参数,而应该这样做:

$carousel.trigger("currentPosition", function( pos ) {
    pos = typeof pos !== 'undefined' ? pos : <?php echo 1;?>;
    console.log(pos);
    var posi = pos;
});

以便在javascript中指定默认函数参数。

编辑:同样的问题出在以下一行:$carousel.trigger("currentPosition", function( pos=2) {

答案 1 :(得分:0)

我建议您使用JavaScript {l}工具,例如JSHintJSLint

主要问题似乎是您正在使用default parameters MDN ,这是一项ECMAScript 6(草案)功能,但未得到广泛支持。

相关问题