请检查jQuery语法

时间:2014-08-23 18:27:02

标签: javascript jquery

我将非常感激sb告诉我下面的代码是否具有正确的语法。

jQuery(document).ready(function ($) { 
  var sliderHeight = $(window).height() - $('.slider').position().top;
  $('.slider').css({'height': sliderHeight});
  $('.landing-title').css({'top': $('.slider').height() / 2 - $('.landing-title').height() / 2}) ;
  $(window).resize(function() {
    sliderHeight = $(window).height() - $('.slider').position().top;
    $('.slider').css({'height': sliderHeight }); 
    $('.landing-title').css({'top': $('.slider').height() / 2 - $('.landing-title').height() / 2});
  });
}

2 个答案:

答案 0 :(得分:1)

代码在语法上是错误的,因为你混淆了函数结束括号。 下面是语法操作代码。希望你能找到帮助。

jQuery(document).ready(function ($) {
    var sliderHeight = $(window).height()-$('.slider').position().top;
    $('.slider').css({ 'height': sliderHeight });
    $('.landing-title').css({ 'top': $('.slider').height()/2 - $('.landing-title').height()/2 }) ;
});

$(window).resize(function(){ sliderHeight = $(window).height()-$('.slider').position().top;
    $('.slider').css({ 'height': sliderHeight });
    $('.landing-title').css({ 'top': $('.slider').height()/2 - $('.landing-title').height()/2 }) ; 
});

答案 1 :(得分:0)

最后一个括号可能是错误的

可能如下所示 });

相关问题