简体   繁体   English

更新我的js手风琴标签以有选择地打开和关闭内容

[英]updating my js accordion tabs to selectively open and close content

I have created an accordion in such a way that only 1 set of content can be open at any one time, my problem is how do I update my code so I can click the active tab and close the content? 我创建手风琴的方式是一次只能打开一套内容,我的问题是如何更新代码,以便单击活动选项卡并关闭内容? At the moment if I try to close the active tab the content slides up and then slides straight back down? 目前,如果我尝试关闭活动标签,则内容会先滑后滑,然后再滑回去?

Im sure I've written this code in the wrong way and would appreciate all advice on how to enhance this http://jsfiddle.net/kyllle/csggQ/1/ 我确定我以错误的方式编写了此代码,并希望获得有关如何增强此http://jsfiddle.net/kyllle/csggQ/1/的所有建议。

Kyle 凯尔

Seems you are over complicating things :) 似乎您正在使事情复杂化:)

You've kinda already made it, http://jsfiddle.net/csggQ/21/ 您已经做到了, http://jsfiddle.net/csggQ/21/

$(document).ready(function(){
    $('p').hide();

    $('h2').click(function() {

        if($(this).hasClass('active'))
        {
           $(this).removeClass('active');
           $(this).next('p').slideUp(600);
        } else {          
           $('#myContent .active').removeClass('active').next().slideUp(600);
           $(this).addClass('active');
           $(this).next('p').slideDown(600);
        }

    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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