简体   繁体   中英

jquery slide an element up and down on click

I am trying to slide an element down when another is click and if that link is then clicked again, slide the element back up, is there a cleaner way of doing it than this?

$("#dropdown, #dropdown span, #dropdown dt a").click(function(event) {
            $("#dropdown dd").slideDown(defaults.speed);
            $("#dropdown").addClass('drop_down_open');
            event.preventDefault();
        });

        $(".drop_down_open, .drop_down_open span, .drop_down_open dt a").click(function(event) {
            console.log("hello");
            $("#dropdown dd").slideUp(defaults.speed);
            event.preventDefault();
        });
$("#anElement").click(function(e) { 
    var theItem = $("#dropdown dd");
    if (theItem.css("display") == none) {
        theItem.slideDown(defaults.speed);
    }
    else {
        theItem.slideUp(defaults.speed);
    }
    e.preventDefault();
});

Modify according to your specific needs.

Is this what you wanted. http://jqueryui.com/demos/accordion/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM