Make slideToggle wait until other div's slideUps have finished?

Samuli Viitasaari

My goal is a specific type of a menu that's divided in four sections that you can open and close by clicking the section headers. Here's what I've so far: http://jsfiddle.net/samuliviitasaari/Ya8P8/9/

This works quite the way I want it to, except for when you already have one menu section open, and then you click another section header. I'd like it to wait until the section closes and only then open the other one; now it's all happening at once, causing some pretty ugly flickering.

My question is, do I have to make the script 'self-aware' (= able to know if a specific section is open or not) or is there a quick way to make the slideToggle automatically wait until the already opened section (if any) has closed. And of course, if there is currently no section open, go straight ahead with no delay?

For now, the core code is pretty crude, trying to close all the other sections just in case, whether they're actually open or not:

$("#one").click(function () {
    $("#toggleone").slideToggle(100);
    $("#toggletwo").slideUp(100);
    $("#togglethree").slideUp(100);
    $("#togglefour").slideUp(100);
});

PS. If you have any other tips on how to make the code more eloquent, I'd be grateful!

Hiral

Try:

I have added toggle class to #toggleone,toggletwo,togglethree,togglefour divs.

$(".toggle").hide();
$("#one,#two,#three,#four").click(function () {
    var id = $(this).attr("id");
    if ($("#toggle" + id).is(":visible")) {
        $("#toggle" + id).slideToggle();
    } else {
        if ($(".toggle:visible").length > 0) {
            $(".toggle:visible").slideUp(function () {
                $("#toggle" + id).slideToggle(200);
            });
        } else {
            $("#toggle" + id).slideToggle();
        }
    }
});

Updated fiddle here.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Make Excel VBA wait until operation is finished

From Dev

Wait until function is finished

From Dev

How to make python wait until the previous task is finished?

From Dev

How to make Gulp wait until dest file is finished?

From Dev

How do I make an Excel RefreshAll wait to close until finished?

From Dev

How to make python wait until the previous task is finished?

From Dev

How to make JS wait until protocol execution finished

From Dev

How to make a python Script wait until download has finished

From Dev

ExecutorService's shutdown() doesn't wait until all threads will be finished

From Dev

Run thread from Tkinter and wait until it's finished

From Dev

Run thread from Tkinter and wait until it's finished

From Dev

Wait until forEach loop is finished?

From Dev

Wait until gobalEval has finished

From Dev

On click myFunction and wait until it is finished

From Dev

Wait until NSURLConnection sendAsynchronousRequest is finished

From Dev

Android AsyncTask wait until finished

From Dev

Wait until my thread is finished

From Dev

Wait until gobalEval has finished

From Dev

Wait until process is finished running

From Dev

C# .Net - How to make application wait until all threads created in Library are finished

From Java

How to wait until all async calls are finished

From Dev

Sequelize wait until loop finished with callback

From Dev

How to wait until an animation is finished in Swift?

From Dev

How to wait until all NSOperations is finished?

From Dev

wait until completion block not finished in AFJSONRPCClient request

From Dev

how to wait until a web request with HttpWebRequest is finished?

From Dev

How to wait until some jQuery methods are finished?

From Dev

How to wait until networking by Alamofire has finished?

From Dev

How to wait until my batch file is finished

Related Related

  1. 1

    Make Excel VBA wait until operation is finished

  2. 2

    Wait until function is finished

  3. 3

    How to make python wait until the previous task is finished?

  4. 4

    How to make Gulp wait until dest file is finished?

  5. 5

    How do I make an Excel RefreshAll wait to close until finished?

  6. 6

    How to make python wait until the previous task is finished?

  7. 7

    How to make JS wait until protocol execution finished

  8. 8

    How to make a python Script wait until download has finished

  9. 9

    ExecutorService's shutdown() doesn't wait until all threads will be finished

  10. 10

    Run thread from Tkinter and wait until it's finished

  11. 11

    Run thread from Tkinter and wait until it's finished

  12. 12

    Wait until forEach loop is finished?

  13. 13

    Wait until gobalEval has finished

  14. 14

    On click myFunction and wait until it is finished

  15. 15

    Wait until NSURLConnection sendAsynchronousRequest is finished

  16. 16

    Android AsyncTask wait until finished

  17. 17

    Wait until my thread is finished

  18. 18

    Wait until gobalEval has finished

  19. 19

    Wait until process is finished running

  20. 20

    C# .Net - How to make application wait until all threads created in Library are finished

  21. 21

    How to wait until all async calls are finished

  22. 22

    Sequelize wait until loop finished with callback

  23. 23

    How to wait until an animation is finished in Swift?

  24. 24

    How to wait until all NSOperations is finished?

  25. 25

    wait until completion block not finished in AFJSONRPCClient request

  26. 26

    how to wait until a web request with HttpWebRequest is finished?

  27. 27

    How to wait until some jQuery methods are finished?

  28. 28

    How to wait until networking by Alamofire has finished?

  29. 29

    How to wait until my batch file is finished

HotTag

Archive