2012-01-21 2 views
-5

Я пытаюсь написать оператор if/else, который будет спрятать мой .thumb<div> при каждом щелчке по ссылкам «about» или «contact». Я хочу, чтобы все из .thumb<div> s сместились вверх.if/else statement

http://dl.dropbox.com/u/14080718/Final/UITabs15.html

У меня нет большого опыта писать, если/иначе statementsI не могу показаться, чтобы выяснить правильный синтаксис любой помощи вы можете дать будет высоко ценится.

 $(function(){ 
    $('.thumb').hide(); 

    $('.subnav').click(function(){ 
     var $menuelement = $('.thumb').eq($(this).closest("li").index());//find the matching nth element in the menu 
     if($menuelement.hasClass('active')){//if clicked element is already expanded 

      $menuelement.removeClass('active').slideUp();//remove the active class and hide it 

     } else {//otherwise,clicked element is not already expanded... 

     if ($('.active').length>0) {//...but another element is expanded 
      $('.active').removeClass('active').slideUp(function(){ 
       $menuelement.addClass('active').slideDown();//add the active class and show it 
      }); 

      } else {//another element is not expanded 

      $menuelement.addClass('active').slideDown();//add the active class and show it 

      } 
     } 
    }); 

    }); 
+7

Пожалуйста, отправьте свой исходный код в вопрос! – deceze

+1

Можете ли вы добавить код, который вы пробовали на свой вопрос? – ThinkingStiff

+0

jQuery - это не язык. – Ryan

ответ

0

Я не могу попробовать это, потому что это немного осиротело, но попробуйте следующую (или по крайней мере следующую идею). Я был смущен, потому что ваша ссылка фактически не содержала код, который вы опубликовали. Попробуйте отправить код jsfiddle с кодом, если у вас все еще есть проблемы.

Ваш оператор $ ('. Active'). Length> 0) не нуждается в части> 0 - все ненулевые длины вернут true.

$(function(){ 
     $('.thumb').hide(); 
     $('.subnav').click(function(){ 
      var menuelement = $('.thumb').eq($(this).closest("li").index());//find the matching nth element in the menu 
      $(menuelement).toggleClass('active').slideToggle(); 
      $('.active').not(menuelement).removeClass('active').slideUp(); 
     }); 
}); 
Смежные вопросы