Jquery accordion slides too many times

I have an accordion, when you click on each button, it expands and displays additional information. It works fine, however every time I press each button to expand it, the window seems to slide up and down like 7/8 times before displaying the content window. I would ideally want it to slide up and down two or three times before showing full content. How best to achieve this.

HTML:

  <div id="ss_menu">
    <h3><b>Winning Ways</b></h3>
  <div class="ss_button">1990-1991</div>
  <div class="ss_content">1st NBA Title<br />
  61 Wins 21 Losses<br />MVP Michael Jordan<br />
  Defeated LA Lakers<br /></div>
  <div class="ss_button">1991-1992</div>
  <div class="ss_content">Repeat Champions<br />
  67 Wins 15 Losses<br />MVP Michael Jordan<br />
  <div class="ss_button">1992-1993</div>
  <div class="ss_content">ThreePeat Champions<br />57 Wins 25 Losses<br />
  MVP Michael Jordan<br />Defeated Phoenix Suns<br /></div>
  <div class="ss_button">1995-1996</div>
  <div class="ss_content">1st NBA Title in 3 years<br />
  72 Wins 10 Losses<b>(NBA history)</b><br />MVP Michael Jordan<br />   
  <b>*Michael Jordan came back from retirement!</b><br />Defeated LA 
  Lakers<br /></div> <div class="ss_button">1996-1997</div>
  <div class="ss_content">2nd Repeat<br />69 Wins 13 Losses<br />
  MVP Michael Jordan<br />Defeated Utah Jazz<br /></div>
 <div class="ss_button">1997-1998</div> <div class="ss_content">
  2nd ThreePeat<br />62 Wins 20 Losses<br />MVP Michael Jordan<br />
  Defeated Utah Jazz<br /></div>
  </div>

CSS

 body {
font-family: Arial, Helvetica, sans-serif;
}

#ss_menu h3{ 
color: white; 
}

#ss_menu { 
width: 200px; 
position:absolute;
right:10px; 
top:825px;
z-index:1
}

.ss_button { 
background-color: black;
border-bottom: 1px solid #FFFFFF;
cursor: pointer;
padding: 10px;
color: #FFFFFF;
    border-radius: 5px;

}

.ss_content {
background-color: #EFEFEF;
display: none;
padding: 10px;
    border-radius: 5px;

}

JS:

 jQuery(function () {
 jQuery('.ss_button').on('click', function () {
    jQuery('.ss_content').slideUp('fast');
    jQuery(this).next('.ss_content').slideDown('fast');
});
});
+4
source share
4 answers

br div 1991-1992 . . https://jsfiddle.net/VixedS/jbz6dxbp/ . , .

  <div class="ss_button">1991-1992</div>
  <div class="ss_content">Repeat Champions<br />
   67 Wins 15 Losses<br />MVP Michael Jordan
  </div>
+1

, ? ( , ajax - ) : "" ".ss_buttons" ".ss_button: not (.processed)".

jQuery(function () {
 jQuery('.ss_button:not(.processed)').on('click', function () {
    jQuery('.ss_content').slideUp('fast');
    jQuery(this).next('.ss_content').slideDown('fast');
 });
 jQuery('.ss_button:not(.processed)').addClass('processed')
});

: html , :

<div id="ss_menu">

 <h3><b>Winning Ways</b></h3>

 <div class="ss_button">1990-1991</div>
  <div class="ss_content">
    1st NBA Title<br />
    61 Wins 21 Losses<br />MVP Michael Jordan<br />
    Defeated LA Lakers<br />
  </div>

 <div class="ss_button">1991-1992</div>
  <div class="ss_content">
    Repeat Champions<br />
    67 Wins 15 Losses<br />
    MVP Michael Jordan<br />
 ***** <-- Should'nt be here a "</div>"

 <div class="ss_button">1992-1993</div>
  <div class="ss_content">
    ThreePeat Champions<br />

 ...

</div>
0

. . preventDefault(). , .

    jQuery('.ss_button').on('click', function (event) {
     event.preventDefault();
    jQuery('.ss_content').slideUp('fast');
    jQuery(this).next('.ss_content').slideDown('fast');
});
0

Source: https://habr.com/ru/post/1620897/


All Articles