2

我正在使用jQuery Accordion并且需要知道面板何时完成加载。我知道我需要绑定accordionchange事件,但是从那里我真的很困惑如何知道面板何时打开。

如果我只是alert()在函数内部放置一个,它会在面板打开后显示,但它也会在面板关闭后显示:

$("#campaigns").accordion({ 
    event: 'click',
    active: false,
    collapsible: true,
    autoHeight: false,
    heightStyle: "content"
}).bind("accordionchange", function(event, ui) {
    alert('Panel opened and closed');
});

我怎样才能知道面板何时完成打开?

4

2 回答 2

2

http://api.jqueryui.com/accordion/#event-activate - 查看事件 - 当面板被激活(打开)时触发。

于 2013-02-14T03:39:03.117 回答
1

Finally got it working how I wanted. Here is how I know when opening a panel:

$("#campaigns").accordion({ 
    event: 'click',
    active: false,
    collapsible: true,
    autoHeight: false,
    heightStyle: "content",
    change: function(event, ui) {

        // See if we are opening a panel
        var allOpen = ui.oldHeader.length == 1 && ui.newHeader.length == 1 && ui.oldContent.length == 1 && ui.newContent.length == 1;
        var newOpen = ui.newHeader.length == 1 && ui.newContent.length == 1;
        if (allOpen || newOpen) {

            // Do something here each time the panel is opened

        }//end if

    }//end change
});

Strangely, change seems to not be documented...

于 2013-02-17T02:40:02.667 回答