请检查jQuery语法

Please check jQuery syntax

本文关键字:语法 jQuery 检查      更新时间:2023-09-26

如果有人告诉我下面的代码语法是否正确,我将非常感激。

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});
  });
}

这段代码在语法上是错误的,因为你混淆了函数结束花括号。下面是经过语法处理的代码。希望对你有帮助。

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 }) ; 
});

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

可以如下所示});