开发者

JQuery Accordion Default State

开发者 https://www.devze.com 2023-02-08 09:44 出处:网络
I need some help with this accordion. Please see the demo here. http://jsfiddle.net/a36RL/ $(document).ready(function() {

I need some help with this accordion. Please see the demo here. http://jsfiddle.net/a36RL/

$(document).ready(function() {
    $('div.accordionButton').click(function() {
        $('div.accordionContent').slideUp('slow');    
        $(this).next().slideDown('slow');
    });
    $("div.accordionContent").hide();
});

I need to make a little开发者_开发问答 changes in it.

  1. I want the first tab down by default.
  2. If a tab is already down, and that tab is clicked again, there should not be anything (Currently it slides up and then down again).

Thanks for the help.


You can trigger the click event on the first button to open the first tab. Try this:

$(document).ready(function() {
    $('div.accordionButton').click(function() {
    if($(this).next().is(":visible")){
        return;
    }

        $('div.accordionContent').slideUp('slow');    
        $(this).next().slideDown('slow');
    });
    $("div.accordionContent").hide();
    $("div.accordionButton:eq(0)").click();
});

Working example @:

http://jsfiddle.net/a36RL/7/

0

精彩评论

暂无评论...
验证码 换一张
取 消