简体   繁体   English

jquery手风琴中的异常效果

[英]Unusual effect in jquery accordion

It's my first question here, I hope you can help me.这是我在这里的第一个问题,我希望你能帮助我。

I'm using an multi level accordion in jQuery but I have a problem.我在 jQuery 中使用了多级手风琴,但我遇到了问题。 When I open a "tab" it open - close - open.当我打开一个"tab"它会打开 - 关闭 - 打开。

Do you have any idea how can I fix this ?你知道我该如何解决这个问题吗?

I left the example with the code:我留下了代码的例子:

http://jsfiddle.net/Wgdx7/2/ http://jsfiddle.net/Wgdx7/2/

 (function(jQuery){
     jQuery.fn.extend({
         accordion: function() {       
            return this.each(function() {

                var $ul                     = $(this),
                    elementDataKey          = 'accordiated',
                    activeClassName         = 'active',
                    activationEffect        = 'slideToggle',
                    panelSelector           = 'ul, div',
                    activationEffectSpeed   = 'fast',
                    itemSelector            = 'li';

                if($ul.data(elementDataKey))
                    return false;

                $.each($ul.find('ul, li>div'), function(){
                    $(this).data(elementDataKey, true);
                    $(this).hide();
                });

                $.each($ul.find('a'), function(){
                    $(this).click(function(e){
                        activate(this, activationEffect);
                        return void(0);
                    });

                    $(this).bind('activate-node', function(){
                        $ul.find( panelSelector ).not($(this).parents()).not($(this).siblings()).slideUp( activationEffectSpeed );
                        activate(this,'slideDown');
                    });
                });

                var active = (location.hash)?$ul.find('a[href=' + location.hash + ']')[0]:$ul.find('li.current a')[0];

                if(active){
                    activate(active, false);
                }

                function activate(el,effect){

                    $(el).parent( itemSelector ).siblings().removeClass(activeClassName).find( panelSelector ).slideUp( activationEffectSpeed, function(){

                    $(el).siblings( panelSelector )[(effect || activationEffect)](((effect == "show")?activationEffectSpeed:false),function(){

                        if($(el).siblings( panelSelector ).is(':visible')){
                            $(el).parents( itemSelector ).not($ul.parents()).addClass(activeClassName);
                        } else {
                            $(el).parent( itemSelector ).removeClass(activeClassName);
                        }

                        if(effect == 'show'){
                            $(el).parents( itemSelector ).not($ul.parents()).addClass(activeClassName);
                        }

                        $(el).parents().show();

                    });
                        });

                }

            });
        }
    }); 
})(jQuery);

$('#accordion').accordion();

Thanks.谢谢。

when I put js file in external sources, it works as expected当我将js文件放在外部资源中时,它按预期工作

EDIT: pasting compressed js text works too...编辑:粘贴压缩的 js 文本也有效...

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

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