Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4548584
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:14:26+00:00 2026-05-21T16:14:26+00:00

I coded an accordion in jquery, It works fairly well however upon closing a

  • 0

I coded an accordion in jquery, It works fairly well however upon closing a previously opened section I get a bounce.

I tried setting an active class and checking for that but ripped it out to save a headache.

My Jquery:

var $runAccordionOnce = 0; var $accordionPrev;

$(document).ready(function(){
    $(".sidebar_game_header").click(function(){
                  if($runAccordionOnce > 0) {

                  $accordionPrev.slideUp('normal');
                  $accordionPrev.prev().css({'background-position' : 'top left'});

                  }

                  $accordionPrev = $(this).next();
                  $(this).next().slideDown('normal');   
                  $(this).css({'background-position' : 'bottom left'});
                  $runAccordionOnce++;            
    });
    });

And a sample of my html, each game section follows this layout:

<div class="sidebar_game_header"><div class="sidebar_game_header_text">Original Titles</div></div>
    <div class="sidebar_game_content">          
    <ul>
        <li><a href="<?php {echo $url . "&amp;game_id=9";} ?>">Game 1</a></li>
            <li><a href="<?php {echo $url . "&amp;game_id=10";} ?>">Game 2</a></li>
            <li><a href="<?php {echo $url . "&amp;game_id=8";} ?>">Game 3</a></li>
    </ul>
    </div>
</div>

The issue seems to be that upon clicking a section header that is already open it will slide up before sliding down again.
The rest works, clicking a different section will close the previously opened one.

This has been driving me crazy for a while. Any tips?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T16:14:27+00:00Added an answer on May 21, 2026 at 4:14 pm

    I believe this should do it. Basically only try to re-display the section if it’s hidden. I wasn’t entirely sure what you wanted to happen when you click on an already open one though. The below code will hide it.

    $(document).ready(function(){
        $(".sidebar_game_header").click(function(){
                      if($runAccordionOnce > 0) {
    
                      $accordionPrev.slideUp('normal');
                      $accordionPrev.prev().css({'background-position' : 'top left'});
    
                      }
    
    
            if($(this).next().is(":hidden")){
                      $accordionPrev = $(this).next();
                      $(this).next().slideDown('normal');   
                      $(this).css({'background-position' : 'bottom left'});
                      $runAccordionOnce++;    
            }        
        });
        });
    

    If you don’t want it hidden, then just check at the very beginning if the one you clicked on is the one in $accordionPrev and don’t hide it.

    var $runAccordionOnce = 0;
    var $accordionPrev;
    
    $(document).ready(function() {
        $(".sidebar_game_header").click(function() {
            if ($runAccordionOnce > 0) {
    
                if ($(this).next()[0] == $accordionPrev[0]) return;
    
                $accordionPrev.slideUp('normal');
                $accordionPrev.prev().css({
                    'background-position': 'top left'
                });
    
            }
    
    
            $accordionPrev = $(this).next();
            $(this).next().slideDown('normal');
            $(this).css({
                'background-position': 'bottom left'
            });
            $runAccordionOnce++;
    
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have done an Accordion style jQuery function which works lovely, but would like
I am working with jQuery UI Accordion and it works great, but I would
I am building a sortable accordion with jquery which works perfectly fine but I
I noticed an issue with my jquery accordion menu. When I open a section
How can I get the active index of the jquery accordion pane when a
I am using JQuery Accordion and it works as it should and opens and
I am populating jQuery accordion from simple xml file, I can get my data
I'd like to add a new section to a Jquery UI accordion when someone
HI, I'm trying to get accordion like functionality without using jQuery's UI accordion feature.
i try to implement the accordion jquery for toggle slide down and slide up

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.