JS主题中出错:意外的令牌函数
Error in JS theme: Unexpected token function
我正在尝试为视图设置动画,我正在将此代码插入到js中,但我在第84行遇到了问题,在:
function trigger_accordion(item-slide) {
if(!(item-slide.is(':animated'))) {
item-slide.trigger('open');
}
}
打印错误:未捕获的SyntaxError:意外的令牌函数
附上完整代码:
(function ($, Drupal) {
var animation = {
'auto_animate': true,
'auto_animate_delay': 8000,
'auto_animate_id': '',
'caption_speed': 'fast',
//'panel_speed': 'slow',
'panel_speed': 1000,
'panel_easing': 'easeInOutCubic'
}
Drupal.behaviors.pamh_theme = {
attach: function(context, settings) {
$(document).ready(function(){
var i = 1;
$('.item-slide').each(function(key, value) {
$(value).attr('id', 'item-slide-'+i);
i++;
});
$('.slide_caption').hide();
$('#item-slide-1 > .slide_caption').show();
$('#item-slide-1').addClass('active');
$('.item-slide').not('.active').children('.slide_image_slice').show();
});
$('.item-slide')
.bind('open', function(){
if(! $(this).hasClass('open')){
$(this).next().trigger('open');
$(this).addClass('open');
$(this).animate({right: "-=769px"}, animation.panel_speed, animation.panel_easing, function(){display_slices();});
}
else{
$(this).prev().trigger('close');
}
$(this).siblings().removeClass('active');
$(this).addClass('active');
setTimeout(function(){hide_slices()},1);
display_caption();
})
.bind('close', function(){
if($(this).hasClass('open')){
$(this).removeClass('open');
$(this).animate({right: "+=769px"}, animation.panel_speed, animation.panel_easing, function(){display_slices();});
$(this).prev().trigger('close');
}
});
$('.item-slide')
.hoverIntent(
function() {
animation.auto_animate = false;
trigger_accordion($(this));
},
function() {
animation.auto_animate = true;
clearInterval(animation.auto_animate_id);
animation.auto_animate_id = setInterval('slideshow_animate()', animation.auto_animate_delay);
}
)
.click(function() {
trigger_accordion($(this));
});
animation.auto_animate_id = setInterval('slideshow_animate()', animation.auto_animate_delay);
};
function trigger_accordion(item-slide) {
if(!(item-slide.is(':animated'))) {
item-slide.trigger('open');
}
}
function display_caption() {
$('.slide_caption').each(function() {
if(!($(this).parent().hasClass('active'))) {
$(this).fadeOut('fast', function() {
$('.item-slide.active > .slide_caption').fadeIn(animation.caption_speed);
});
}
});
}
function hide_slices() {
$('.slide_image_slice').each(function() {
if($(this).parent().hasClass('active')) {
$(this).fadeOut('fast');
}
});
}
function display_slices() {
$('.slide_image_slice').each(function() {
if(!$(this).parent().hasClass('active') && !$(this).is(":visible")) {
$(this).fadeIn('fast');
}
});
}
function slideshow_animate() {
if(!animation.auto_animate) return;
var next_slide = $('.item-slide.active').next();
if(!next_slide.length) {
next_slide = $('#item-slide-1');
}
next_slide.click();
}
};
})(jQuery, Drupal);
两件事:
- 不能像使用
item-slide
那样使用-
字符命名javascript变量。使用CSS类是可以的,但使用javascript必须找到其他东西 -
你的右括号
}
放错地方了。以下是适用于我的完整代码:(function ($, Drupal) { var animation = { 'auto_animate': true, 'auto_animate_delay': 8000, 'auto_animate_id': '', 'caption_speed': 'fast', //'panel_speed': 'slow', 'panel_speed': 1000, 'panel_easing': 'easeInOutCubic' } Drupal.behaviors.pamh_theme = { attach: function(context, settings) { $(document).ready(function(){ var i = 1; $('.item-slide').each(function(key, value) { $(value).attr('id', 'item-slide-'+i); i++; }); $('.slide_caption').hide(); $('#item-slide-1 > .slide_caption').show(); $('#item-slide-1').addClass('active'); $('.item-slide').not('.active').children('.slide_image_slice').show(); }); $('.item-slide') .bind('open', function(){ if(! $(this).hasClass('open')){ $(this).next().trigger('open'); $(this).addClass('open'); $(this).animate({right: "-=769px"}, animation.panel_speed, animation.panel_easing, function(){display_slices();}); } else{ $(this).prev().trigger('close'); } $(this).siblings().removeClass('active'); $(this).addClass('active'); setTimeout(function(){hide_slices()},1); display_caption(); }) .bind('close', function(){ if($(this).hasClass('open')){ $(this).removeClass('open'); $(this).animate({right: "+=769px"}, animation.panel_speed, animation.panel_easing, function(){display_slices();}); $(this).prev().trigger('close'); } }); $('.item-slide') .hoverIntent( function() { animation.auto_animate = false; trigger_accordion($(this)); }, function() { animation.auto_animate = true; clearInterval(animation.auto_animate_id); animation.auto_animate_id = setInterval('slideshow_animate()', animation.auto_animate_delay); } ) .click(function() { trigger_accordion($(this)); }); animation.auto_animate_id = setInterval('slideshow_animate()', animation.auto_animate_delay); } }; function trigger_accordion(itemSlide) { if(!(itemSlide.is(':animated'))) { itemSlide.trigger('open'); } } function display_caption() { $('.slide_caption').each(function() { if(!($(this).parent().hasClass('active'))) { $(this).fadeOut('fast', function() { $('.item-slide.active > .slide_caption').fadeIn(animation.caption_speed); }); } }); } function hide_slices() { $('.slide_image_slice').each(function() { if($(this).parent().hasClass('active')) { $(this).fadeOut('fast'); } }); } function display_slices() { $('.slide_image_slice').each(function() { if(!$(this).parent().hasClass('active') && !$(this).is(":visible")) { $(this).fadeIn('fast'); } }); } function slideshow_animate() { if(!animation.auto_animate) return; var next_slide = $('.item-slide.active').next(); if(!next_slide.length) { next_slide = $('#item-slide-1'); } next_slide.click(); } })(jQuery, Drupal);
相关文章:
- React JS:未捕获(在承诺中)语法错误:在位置 0 的 JSON 中意外<令牌
- jQuery$.getJSON抛出意外令牌
- 为什么我在下面的..of循环中得到意外令牌
- 组件中的ReactJS意外令牌
- AngularJS $http GET 请求到本地 JSON 文件返回语法错误:意外令牌]
- 巴别塔,意外令牌 (15:33) ::.
- Sencha 2.0 和 Codeigniter RESTful API 生成未捕获的语法错误:意外令牌:
- 在事件上使用 jquery 时出现意外令牌
- JSON 中位置 4 处的意外令牌<
- 意外令牌 ) 在我的代码中
- Electron 和 Babel 6 异步/等待抛出意外令牌
- “JSON.parse(str)”返回“意外令牌c”,但str是一个字符串
- jQuery after() uncatch SyntaxError: 意外令牌 ILLEGAL
- 使用节点javascript的意外令牌ILLEGAL
- Javascript/JQuery-Chrome意外令牌
- Ajax 帖子未捕获语法错误:意外令牌非法
- angularjs-SyntaxError:请求从服务器返回时出现意外令牌
- jquery:使用ember的意外令牌C
- React本机项目中的意外令牌
- 解析有效的 JSON 得到“语法错误:意外令牌非法”