如果选择器链接?

cas*_*n79 0 jquery css-selectors

好吧,即使选定的ID具有选定的类,我也会尝试将某些内容设置为不同的高度.我有以下代码.

 function myfunction() {


   if ($('#homebutton').hasClass("active"));
   {
    $('#content').animate({height: "240px",opacity: 1}, 100 , hideLoader());
   }

   if ($('#showbutton').hasClass("active"));
   {
   $('#content').animate({height: "79px",opacity: 1}, 200 , hideLoader());
   }

   if ($('#aboutbutton').hasClass("active"));
   {
   $('#content').animate({height: "527px",opacity: 1}, 300 , hideLoader());}

   if ($('#contactbutton').hasClass("active"));
   {
   $('#content').animate({height: "1040px",opacity: 1}, 400 , hideLoader());
   }
}
Run Code Online (Sandbox Code Playgroud)

无论我点击什么,它都会在彼此之后将动画链接起来,结果是1040px高,我做错了什么?

试着改变它

{if ($('#homebutton').hasClass("active"));
$('#content').animate({height: "240px",opacity: 1}, 100 , hideLoader());
}
Run Code Online (Sandbox Code Playgroud)

绝对没有效果

Guf*_*ffa 5

您已将if语句与下一行的代码分开.条件为真时执行的唯一事情是空语句.

改变这个:

if ($('#homebutton').hasClass("active"));
Run Code Online (Sandbox Code Playgroud)

成:

if ($('#homebutton').hasClass("active"))
Run Code Online (Sandbox Code Playgroud)

和其他三个相同.