1

我根据一个找到的 jquery ui 创建了简单的手风琴菜单。我在为元素设置动画时遇到问题,单击时我无法正确使用向上或向下滑动动画,并且如果使用它,还会出现许多其他问题。因此,任何帮助都将有助于获得动画。

JS 小提琴:http: //jsfiddle.net/cZbr6/

脚本

            $(document).ready(function() {

                var notfContainer = $('#notifications');

                notfContainer.find("a").each(function() {
                    var e = $(this);
                    if(!e.hasClass('active')) {         
                                e.next().css({
                                    'display':'none'
                                });     //hide all other div's and set height as 0px

                    }       
                });



                notfContainer.on('click' , function(event) {
                    var target = $(event.target);       //Used to find the element on which the click event has happened.

                    if(target.is("a")) {                //If the click event occurred on <a>
                        var self = $(target);           //Select the element
                        if(self.hasClass('active')) {   //If is is already expanded .. has active class
                            return;                     //just .. return 
                        }else {

                        notfContainer.find("a").each(function() {
                            var e = $(this);
                            if(e.hasClass('active')) {  
                                        e.removeClass('active');
                                        e.next().css('display','none');     //hide all other div's
                                        return false;   //break the loop    
                            }   


                        });
                            self.addClass('active');    
                            self.next().css({
                                'display':'block',
                                'height':'160px'
                            });


                        }


                    }
                });

            });
4

1 回答 1

2

jsBin 演示

jQuery:

$(document).ready(function() {

    $('#notifications a.active').next('div').siblings('div').hide();
  
    $('#notifications a').click(function() {
        $(this).addClass('active').siblings('a').removeClass('active');
        var el = $(this).next('div');
        check = (el.is(':visible')) ? el.slideUp() : function(){ $('#notifications div').slideUp(); el.slideDown(); }();
    });
    
});
于 2012-05-13T20:04:06.347 回答