jQuery - 函数体之后缺少语法错误}

时间:2013-05-23 02:54:19

标签: jquery

抱歉,我不是程序员。我正在为自己构建一个个人WordPress网站,我不得不编辑php文件,我遇到了这个问题。请有人帮助我......

答案谢谢大家:D它正在运作,有时候我很惊讶我是多么愚蠢:P

萤火虫:

SyntaxError: missing } after function body
[Break On This Error]   

...){           var $container = $('#portfolio');               //load with opacity if fade i...

代码:

jQuery(document).ready(function ($) {
  var $container = $('#portfolio');
  //load with opacity if fade in is off
  if ($('#portfolio').attr('data-fade') != 1) {
    $('#portfolio.portfolio-items .col.span_<?php echo $span_num; ?>').css('opacity', 1);
  }
  //else show the loading gif
  else {
    $('.container.main-content').before('<span id="portfolio-loading"><span>');
  }
  $(window).load(function () {
    // initialize isotope
    $container.isotope({
      itemSelector: '.element',
      filter: '*',
      masonry: {
        columnWidth: $container.width() / <? php echo $cols; ?>
      }
    });
    //fade in
    if ($('#portfolio').attr('data-fade') == 1) {
      //fadeout the loading animation
      $('#portfolio-loading').stop(true, true).fadeOut(300);
      //fadeIn items one by one
      $('#portfolio.portfolio-items .col.span_<?php echo $span_num; ?>').css('opacity', 0);
      $('#portfolio.portfolio-items .col.span_<?php echo $span_num; ?>').each(function (i) {
        $(this).delay(i * 150).animate({
          'opacity': 1
        }, 350);
      });
    }
  });

4 个答案:

答案 0 :(得分:3)

在结尾添加一个});以关闭jQuery(document).ready(function ($) {

答案 1 :(得分:3)

});放在代码的末尾

答案 2 :(得分:0)

请参阅下面的评论:

jQuery(document).ready(function ($) {
    var $container = $('#portfolio');
    //load with opacity if fade in is off
    if ($('#portfolio').attr('data-fade') != 1) {
        $('#portfolio.portfolio-items .col.span_<?php echo $span_num; ?>').css('opacity', 1);
    }
    //else show the loading gif
    else {
        $('.container.main-content').before('<span id="portfolio-loading"><span>');
    }
}); //---> You were  missing this
$(window).load(function () {
    // initialize isotope
    $container.isotope({
        itemSelector: '.element',
        filter: '*',
        masonry: {
            columnWidth: $container.width() / '<? php echo $cols; ?>' //--> I am no expert in PHP but I think you need this inside single quotes
        }
    });
    //fade in
    if ($('#portfolio').attr('data-fade') == 1) {
        //fadeout the loading animation
        $('#portfolio-loading').stop(true, true).fadeOut(300);
        //fadeIn items one by one
        $('#portfolio.portfolio-items .col.span_<?php echo $span_num; ?>').css('opacity', 0);
        $('#portfolio.portfolio-items .col.span_<?php echo $span_num; ?>').each(function (i) {
            $(this).delay(i * 150).animate({
                'opacity': 1
            }, 350);
        });
    }
});

答案 3 :(得分:0)

jQuery(document).ready(function ($) {
    var $container = $('#portfolio');
    //load with opacity if fade in is off
    if ($('#portfolio').attr('data-fade') != 1) {
        $('#portfolio.portfolio-items .col.span').css('opacity', 1);
    }
    //else show the loading gif
    else {
        $('.container.main-content').before('<span id="portfolio-loading"><span>');
    }

    $(window).load(function () {

        // initialize isotope
        $container.isotope({
            itemSelector: '.element',
            filter: '*',
            masonry: {
                columnWidth: $container.width()
            }
        });

        //fade in
        if ($('#portfolio').attr('data-fade') == 1) {

            //fadeout the loading animation
            $('#portfolio-loading').stop(true, true).fadeOut(300);

            //fadeIn items one by one
            $('#portfolio.portfolio-items .col.span_<?php echo $span_num; ?>').css('opacity', 0);

            $('#portfolio.portfolio-items .col.span_<?php echo $span_num; ?>').each(function (i) {
                $(this).delay(i * 150).animate({
                    'opacity': 1
                }, 350);
            });
        }
    });
});

固定。