Javascript 手风琴if/else逻辑

Javascript 手风琴if/else逻辑,javascript,jquery,animation,if-statement,accordion,Javascript,Jquery,Animation,If Statement,Accordion,我猜我的if/else逻辑是错误的。基本上,我有一个手风琴结构,在页面加载时,第一个手风琴窗格显示一半,高度为150px。然后,当用户单击accordion标头时,它将完全打开,高度为320px。在下一次单击时,它应该关闭,并像其他具有标准隐藏/显示的手风琴元素一样正常工作。它目前工作正常,但并不平滑,在完全显示之前,手风琴窗格关闭 以下是html: <div class="accordion"> <h3 class="acc-header glanceH">

我猜我的if/else逻辑是错误的。基本上,我有一个手风琴结构,在页面加载时,第一个手风琴窗格显示一半,高度为150px。然后,当用户单击accordion标头时,它将完全打开,高度为320px。在下一次单击时,它应该关闭,并像其他具有标准隐藏/显示的手风琴元素一样正常工作。它目前工作正常,但并不平滑,在完全显示之前,手风琴窗格关闭

以下是html:

<div class="accordion">
      <h3 class="acc-header glanceH">At a glance</h3>
      <div class="acc-content glanceC slider" >
        <div class="hero-video">
        </div>
      </div>
      <h3 class="acc-header">What we do</h3>
      <div class="acc-content" >
        <div class="hero-video what-we-do">
        </div>
      </div>
      <h3 class="acc-header">How we do it</h3>
      <div class="acc-content how" >
      </div>
      <h3 class="acc-header">Where we reach</h3>
      <div class="acc-content where" >
      </div>
      <h3 class="acc-header">How</h3>
      <div class="acc-content" >
      </div>
    </div>

更新:哎呀,如果我读了问题-:p


“埃芬天才。工作是一种享受。非常感谢。现在我只需要想一想:)
//generally slides all accordion elements with class "acc-content" when div with class "acc-header" is clicked 

$('.acc-header').click(function(e) {
        e.preventDefault();
        $(this).toggleClass('acc-active');
        $(this).next('.acc-content').slideToggle(200).siblings('.acc-content').slideUp(200);
        $(this).siblings().removeClass('acc-active');       
    });

//when the page loads 'peek' at the content of the first accordion content (to 150px depth)

    $('.slider').css('height','150px');
    $('.slider').animate({ height: 'show'}, 'slow').addClass('itsopen');    

//if its already been opened, close it, else open it to 320px

    $('.glanceH').click(function() {
              if(!$(this).hasClass('acc-active')) {
                    $(this).next().siblings('.acc-content').slideUp(2000);
                    $(this).siblings().removeClass('acc-active');
                }
              else if($('.slider').hasClass('itsopen')){
                    $('.slider').animate({ height: 320}, 'slow');
                }
     });
//generally slides all accordion elements with class "acc-content" when div with class "acc-header" is clicked
$('.accordion .acc-header').click(function() {
    var first = $('.slider');

    // open peek if clicked, otherwise hide it
    if (first.is('.itsopen')) {
        if ($(this).next().is('.acc-active')) {
            // open peek to full height
            first.removeClass('itsopen').animate({ height: '320px' }, 'slow');
            return;
        } else {
            // close first because a different header was clicked
            first.removeClass('itsopen acc-active').slideUp('slow');
        }
    }

    // remove active class from all content
    $('.acc-content').removeClass('acc-active');
    // show active content
    $(this).next().addClass('acc-active').toggle('slow');
    // close all content that isn't active
    $('.acc-content:not(.acc-active').slideUp('slow');
    return false;

})
// initialize accordion with all content closed
.next().hide();

//when the page loads 'peek' at the content of the first accordion content (to 150px depth)
$('.slider')
    .css({ height: '0px' })
    .show()
    .animate({ height: '150px' }, 'slow')
    .addClass('itsopen acc-active');