Javascript 未捕获的语法错误:意外标记=
我在Joomla中使用滑块滚动图像,但我的js在fire fox中运行良好,但它显示未捕获 语法错误: 意外标记=chrome中出现错误 我的代码是:Javascript 未捕获的语法错误:意外标记=,javascript,jquery,google-chrome,joomla2.5,Javascript,Jquery,Google Chrome,Joomla2.5,我在Joomla中使用滑块滚动图像,但我的js在fire fox中运行良好,但它显示未捕获 语法错误: 意外标记=chrome中出现错误 我的代码是: var $j = jQuery.noConflict(); $j(document).ready(function () { function animateThumbs( direction, $item, val, opacity ) { var ani = { opacity: opacity
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;
});
});
var$j=jQuery.noConflict();
$j(文档).ready(函数(){
函数animateThumbs(方向、$item、val、不透明度){
var ani={
不透明度:不透明度
};
ani[getMarginProperty()]=val;
如果(方向==“下一步”){
变量x1='.t1',
x2='.t2,.t4',,
x3='.t3、.t5、.t7',
x4='.t6,.t8',
x5='.t9';
}否则{
变量x1='.t9',
x2='.t6、.t8',
x3='.t3、.t5、.t7',
x4='.t2,.t4',,
x5='.t1';
}
$j(x1,$item)。延迟(_持续时间*0)。设置动画(ani,_持续时间);
$j(x2,$item)。延迟(_持续时间*0.25)。动画(ani,_持续时间);
$j(x3,$item)。延迟(_持续时间*0.5)。动画(ani,_持续时间);
$j(x4,$item)。延迟(_持续时间*0.75)。动画(ani,_持续时间);
$j(x5,$item)。延迟(_持续时间*1)。设置动画(ani,_持续时间);
}
函数getMarginProperty(){
返回(_orientation=='horizontal')?'marginLeft':'marginTop';
}
函数getMargin(方向){
变量边距=($window[(_-orientation='horizontal')?'width':'height']()/2)+210
如果(方向==“下一步”)
{
保证金=-保证金;
}
收益率;
}
变量$window=$j(window),
$inner=$j(“#inner”),
$carousel=$j(“#carousel”);
变量_方向='水平',
_持续时间=500,
_动画=假;
$inner.show();
$carousel.carouFredSel({
宽度:“100%”,
高度:“100%”,
通告:错,,
无限:错,
方向:'对',
项目:1,
汽车:错,
滚动:{
外汇:“无”,
超时持续时间:500,
条件:功能(方向){
_动画=真;
if($carousel.hasClass('prepared'))
{
$carousel.removeClass('prepared');
返回true;
}
$carousel.addClass('prepared');
animateThumbs(方向,$carousel.children().first(),getMargin(方向),0);
设置超时(
函数(){
$carousel.触发器(方向);
},_持续时间+300
);
返回false;
},
onBefore:函数(数据){
变量方向=data.scroll.direction;
变量css={
不透明度:0
};
css[getMarginProperty()]=-getMargin(方向);
$j('img',data.items.visible).css(css);
animateThumbs(方向,data.items.visible,0,1);
},
onAfter:函数(数据){
data.items.old.children().css({
“marginLeft”:0,
“marginTop”:0
});
设置超时(
函数(){
_动画=假;
},_持续时间+800
);
}
}
});
$carousel.trigger(“当前位置”,函数(位置=){
控制台日志(pos);
var-posi=pos;
});
$j(“#左”)。单击(函数(){
如果(_设置动画){
返回false;
}
var direction=this.id,
滚动='prev',
新方向=(方向=‘向上’| |方向=‘向下’)?‘垂直’:‘水平’;
如果(_方向!=新方向){
_方向=新方向;
$internal.toggleClass('horizontal').toggleClass('vertical');
$carousel.trigger('configuration',['direction',direction]);
}
$carousel.触发器(“当前位置”,函数(位置=2){
//控制台日志(pos);
如果(pos>0&&pos,我建议您使用JavaScript linting工具,例如或
主要的问题似乎是您使用的是MDN,这是一种ECMAScript 6(草稿)功能,它没有得到广泛的支持。您没有为错误提供行号,但是看到您的代码,我假设错误出现在以下行:$carousel.trigger(“currentPosition”,function(pos=){
javascript不允许这样的默认参数,相反,您应该:
$carousel.trigger("currentPosition", function( pos ) {
pos = typeof pos !== 'undefined' ? pos : <?php echo 1;?>;
console.log(pos);
var posi = pos;
});
$carousel.trigger(“当前位置”,函数(位置){
pos=pos的类型!=“未定义”?pos:;
控制台日志(pos);
var-posi=pos;
});
以便在javascript中指定默认函数参数
编辑:同样的问题出现在下面这行:$carousel.trigger(“currentPosition”,function(pos=2){
几十行代码,寻找一个甚至没有行号的语法错误。我不这么认为。你真的不希望我们看到“=”的每一次出现在这个代码片段中,您知道吗?请指出错误发生的位置。如果代码的第一行似乎遗漏了4个空格,将被呈现为代码…请使用firebug查看行号。javascript中有一些未解析的php代码。该行似乎是导致错误的原因。$carousel.trigger(“currentPosition”,function(pos=){
ya我尝试删除pos=但它显示了相同的错误,并且在第353行显示了错误,但我的代码只有240行,这是一个问题,我正面临您的回答,但我收到了“未捕获的语法错误:意外的字符串”错误。非常感谢