Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove slideUp in jquery

I want to remove these Slide up function

$( document ).ready(function() {
    $("#tabBar ul.buttons > li > a").on("click", function(e){
        //if submenu is hidden, does not have active class
        if(!$(this).hasClass("active")) {

            // hide any open menus and remove active classes
            $("#tabBar ul.buttons li ul").slideUp(350);
            $("#tabBar ul.buttons li a").removeClass("active");

            // open submenu and add the active class
            $(this).next("ul").slideDown(350);
            $(this).addClass("active");

        //if submenu is visible
        }else if($(this).hasClass("active")) {

            //hide submenu and remove active class
            $(this).removeClass("active");
            $(this).next("ul").slideUp(350);
        }
    });
});

when i add another div to the body by Jquery

$(document).ready(function(){
    $(".Collapse_menu").click(function(){
        $(".bodyStatic").toggleClass("collapse-body");
        //comment: here i want to add my code so that when i call collapse-body the top slide up function should remove
    });
});

I am making a collapsable menu here are the images which helps you for better understanding

enter image description here enter image description here

like image 323
moidul dargahi Avatar asked Dec 25 '15 06:12

moidul dargahi


2 Answers

This is my try

if($(".bodyStatic").hasClass("collapse-body"))
{
    //DO NOTHING
}
else
{
    $(this).next("ul").slideUp(350);
}

//OR VICE VERSA
like image 114
Hemal Avatar answered Nov 18 '22 21:11

Hemal


As per my understanding whenever you click on .Collapse_menu, you want to collapse the horizontally expanded menu as well as close the vertically opened submenu. If this is the case then you may want to try below code:

Code1:

$( document ).ready(function() {
    $("#tabBar ul.buttons > li > a").on("click", function(e){

        if($(".bodyStatic").hasClass("collapse-body"))
        {
            $(".bodyStatic").removeClass("collapse-body")
        }
        //if submenu is hidden, does not have active class
        if(!$(this).hasClass("active")) {

            // hide any open menus and remove active classes
            $("#tabBar ul.buttons li ul").slideUp(350);
            $("#tabBar ul.buttons li a").removeClass("active");

            // open submenu and add the active class
            $(this).next("ul").slideDown(350);
            $(this).addClass("active");

        //if submenu is visible
        }else if($(this).hasClass("active")) {

            //hide submenu and remove active class
            $(this).removeClass("active");
            $(this).next("ul").slideUp(350);
        }
    });
});

Code2:

$(document).ready(function(){
    $(".Collapse_menu").click(function(){
        $(".bodyStatic").toggleClass("collapse-body");

        var activeSubmenu = $("#tabBar ul.buttons > li > a.active"); //grab the active submenu if any
        //hide submenu and remove active class
        $(activeSubmenu).removeClass("active");
        $(activeSubmenu).next("ul").slideUp(350);
    });
});

Please let me know the outcome.

like image 42
vijayP Avatar answered Nov 18 '22 22:11

vijayP